#How to let character2d(player) collide to Area 2D but stop the movement
1 messages · Page 1 of 1 (latest)
use some staticbody2ds on the borders of the game
but if its the whole screen you might need to hack some code to make it work with every display it runs on
In your player move function, clamp the player's position. global_position = global_position.clamp(Vector2.ZERO, Vector2(1152, 648)
You'll want to get the viewport dimensions too, that's with get_visible_rect().size I think
And then also when you clamp it will be useful to add and subtract the player's size so it doesn't go off the screen a bit so like if your player is 100px wide and 200 px tall then clamp it with Vector2.ZERO + player_size/2 ! and screen_size - player_size/2
Since the player's origin is in the middle it'll be good to use half its size