0 votes

After flipping the sprite I had to flip the collision polygon. I used this code to do the flipping:

$CollisionPolygon2D.scale.x *= -1

The problem is that after this the program takes the collision polygon's x value as it's bottom right corner, instead of it's bottom left corner (not 100% sure about this, but I think this is what is happening). Because of this this the sprite and CollisionPolygon2D are not alined.![][1]![][2] I have tried everything i could think of but nothing woks.

Thank you in advance :)

in Engine by (12 points)

1 Answer

+1 vote

i might be wrong but i think is not recommended to affect the shape of collision shapes and polygons using Transform because it can affect the behaviour of the physics. with CollisionPolygon2D you can re-arrange the position of the PoolVector2Array points of the polygon property in the inspector setting them to new positions when your character flips
like:

func facing_left():
  player_collision_polygon.polygon[0] = Vector2(-32, 0)
  player_collision_polygon.polygon[1]= Vector2(32, 0)
func facing_right():
  player_collision_polygon.polygon[0] = Vector2(32, 0)
  player_collision_polygon.polygon[1]= Vector2(-32, 0)

that's just an example of moving the first two points but Polygon shapes contain at least 3 points so you get the idea.

by (428 points)
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.