Activity
Mon
Wed
Fri
Sun
Jan
Feb
Mar
Apr
May
Jun
Jul
Aug
Sep
Oct
Nov
What is this?
Less
More

Memberships

Ooga Booga Game Devs

3.1k members • Free

8 contributions to Ooga Booga Game Devs
Raylib screen position to world position
If you're using Raylib instead of Ooga Booga, and want to get the world position from your cursor for example, this may be of use: Vector2 screen_position_to_world_position(Vector2 screen_position, Camera2D camera) { Vector2 world_position = (Vector2){ .x = (screen_position.x / camera.zoom) + camera.target.x - (camera.offset.x / camera.zoom), .y = (screen_position.y / camera.zoom) + camera.target.y - (camera.offset.y / camera.zoom), }; return world_position; } Edit: As @Alperen Yilmaz pointed out, you could also use the function GetScreenToWorld2D that comes with Raylib.
2 likes • Aug '24
@Alperen Yilmaz I think so. I will update the post to mention this. Thank you btw, I tried checking if there existed one built into Raylib, but I didn't find any.
3 likes • Aug '24
@Rayner Tan I haven't dealt with it yet, and I don't know of any good fixes for it other than just ignoring the input if it's 0,0. It's a bit of a hack, but it'll probably work just fine.
Basic top-down movement physics
I haven't watched all the videos in the classroom yet, but I noticed that Randy mentioned that better movement physics is difficult, which it can be, but it doesn't have to. You can get away with just having a velocity vector, a position vector, movement speed, and friction. The friction makes sure the player can't get infinite velocity and makes sure the velocity doesn't get set to 0 immediately after you stop pressing any input buttons. Though you could have a max speed and clamp the player velocity, you could do this using the clamp macro in linmath.c. For example: // Globals / state #define MOVEMENT_SPEED 20.0f #define MOVEMENT_FRICTION 50f Vector2 velocity = v2(0, 0); Vector2 position = v2(0, 0); // Get the input direction. Vector2 direction = v2(0, 0); if (is_key_down('W')) direction.y += 1; if (is_key_down('S')) direction.y -= 1; if (is_key_down('A')) direction.x -= 1; if (is_key_down('D')) direction.x += 1; // Normalize the direction. direction = v2_normalize(direction); // Scale the direction to the movement speed. direction = v2_mulf(direction, MOVEMENT_SPEED * delta_t); // Include new movement in velocity velocity = v2_add(velocity, direction); // Apply friction velocity = v2_mulf(velocity, MOVEMENT_FRICTION * delta_t); // Set velocity to 0 if too low if (v2_length(velocity) < 0.1f) velocity = v2(0, 0); // Apply velocity position = v2_add(position, velocity); Believe it or not, but that is all you need to have some basic movement with acceleration and deceleration. If you want to make it a bit more fancy you could for example only apply the friction when there is no input (when the length of direction is 0) so it only decelerates when you aren't moving, and you can better control the movement speed, but then you should also set a max speed using clamp.
Questions - Basic player movement
THE FIRST REAL EP OF PROGRAMMING! LESGOOOOOOOO leave your Qs down below!
Questions - Basic player movement
4 likes • Aug '24
@Luke Ingram btw, 3blue1brown has a really good video series about linear algebra where he explains it all visually. (Linear algebra is scalars, vectors, matrices, etc) https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab
3 likes • Aug '24
There is music on Itch: https://itch.io/game-assets/tag-music/tag-royalty-free
Share your project fork!
Make sure your fork of the ooga booga repo is public and comment a link to it down below.
3 likes • Aug '24
As I am on Linux, I have decided to go with Raylib instead. Here is my repo: https://git.sr.ht/~marvhus/Darker
1-8 of 8
Martin Husby
3
34points to level up
@martin-husby-4195
Programmer | Game Dev

Active 364d ago
Joined Aug 12, 2024
Norway