Problems with flipping CollisionPolygon2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By banana_bush

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 :slight_smile:

:bust_in_silhouette: Reply From: vnmk8

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

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.