#How to let character2d(player) collide to Area 2D but stop the movement

1 messages · Page 1 of 1 (latest)

flat ocean
#

I want to create an mobile application in portrait mode and want the character2d(player) does not go beyond the outside of viewport but when I test my application by putting aread2d there it still let the player to collide and some of parts go there and then player get stuck there any help please

rancid pivot
#

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

cloud robin
#

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

flat ocean
#

But i need to make sure when player is dragged using touch only allows to be viewport only does not allow go outside of viewport but can collide the wall and it still moves

#

I added this code for move test: