Aug '24 (edited) • VALUE
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.
5
8 comments
Martin Husby
3
Raylib screen position to world position
powered by
Ooga Booga Game Devs
skool.com/game-dev-grinders-8513
A group for game devs who want to ship great games from scratch in C, while mastering the ancient art of Caveman Programming
Build your own community
Bring people together around your passion and get paid.
Powered by