0 votes

What I've done is that I flip the player depending on what arrow button the user has pressed. I use self.scale.x *= -1 to do that. The problem is that if I flip the player near a wall some collisionshape2d go inside the wall which results in the player being stuck. I have thought of a work around by adding an area2D on top of wall and using its onbodyentered signal to push the player away. But the problem with it is that I'll have to do that with all the tiles. Is there any better way to solve this problem? Thanks in advance
Video showing the problem

in Engine by (12 points)

it looks to me the collision area at the bottom is not symmetric relative to the filp axis, and when you flip, it goes inside the wall, stucking the character.
does it work if you fix the symmetry?

No the problem wasn't the symmetry, when flipping on the horizontal axis the sprite's left foot would be inside the wall. And i've made the bottom collision in a way that it covers both feet so that way the collision would also go inside the wall. I've implemented a workaround to this problem by using raycasts to detect walls, so that way when i'm calling the flip function i'll use the raycast to see if the character is next to a wall. If it is then after flipping i'll increment/decrement the self.position.x of the character a few pixels away from the wall depending on whether the wall is on the right or left. I'll be happy to hear some better solutions for this problem. Thanks

when flipping on the horizontal axis the sprite's left foot would be inside the wall.

yeah exactly, because it is not symmetrical.
just move the collision rectangle on the foots so that its center is positionated on the center of the character node, in this way the AABB rectangle will be positionated exactly in the same position when flipped, instead of slighlty translated.

you wont need any raycast then.

the other thing you can do is to flip the sprite only, and do not touch the collision poligon on the bottom.

I implemented that and that has fixed the issue. The character is no longer getting stuck on walls. But the character is also no longer walking next to a wall because of the increased size of the collisionshape at the bottom. It looks as if there is an invisible box infront of the character (because of the increased size of the collsiion shape). This looks kinda odd don't you think? I attached a link with the video below so you can get the idea.

Video Link

And also in the code i only flipped the sprite, head collision and body collision, didn't touch the feet collision.

well that's a simple issue due to the character picture not being positionated exacty in the center of the sprite (the character is mostly on one side, the sword is on the other).
if you dont like this, simply move the sprite relatively to the node so that the character is roughly on the center.
Then, you can reduce the collision polygon on the bottom to the real dimension of the feet.
Just remember that collision node need to be positionated exactly in the center of the character node, only the sprite can be translated

Ohh got it. It works now. Thank you so much for the help. Really appreciate it

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.