How to use Transform2D to flip a node

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

Hi,

I’m trying implement a ragdoll effect in my 2D game. This is done by instancing a PackedScene ragdoll (made of Rigidbody2D) and adjusting each limbs’ position and rotation according to those of the original player. This works when the player’s scale.x = 1, but is no good when flipped horizontally so scale.x = -1. The ragdoll appears to explode.

With a bit of research I think this can be sorted by using some of the Transform2D methods, but I’m not sure exactly which ones. I think the process should be:

  1. Get player limb position and rotation.
  2. Get player scale and rotation to determine player’s local x-axis.
  3. Flip limb position along player’s local x-axis.

Could anyone explain how this might be done in GDScript? Thanks