Flip animation by setting X scale of parent causing sprite to flip h/v randomly

Godot Version

4.3

Question

I have an AnimationPlayer with animations I’d like to flip. I googled and found people are doing this by setting a negative scale on the parent node. Great - that can handle my AnimatedSprite2D flipping too. So I implemented that:

This seems to work well, apart from the fact that when the animation plays (the death animation is the only animation to use the AnimationPlayer at the moment - the walk animations are all in the AnimatedSprite2D), I get random horizontal and vertical flipping going on. Here’s the animation tracks:

video of the problem

Is this a bug?

The sprite doesn’t look doing only the x flip, looks doing an entire 360 rotation, are you sure you’re not doing this inside your animation? You’re animating nodes rotation there. You also can disable the _process callback when the enemy dies with set_process(false) to see if you’re not doing unecessary flips after dead.

1 Like

You also can disable the _process callback when the enemy dies with set_process(false) to see if you’re not doing unecessary flips after dead.

That would help isolate the problem, yeah. Let me just check…

So if I move the scale assignment to my AI logic, which is the only time the direction var “dir” is set, the sprite does not flip at all. It does seem to flip for a single frame. So I guess something else is overwriting the transform.

Ok, I found it - it’s this:

Note: Negative X scales in 2D are not decomposable from the transformation matrix. Due to the way scale is represented with transformation matrices in Godot, negative scales on the X axis will be changed to negative scales on the Y axis and a rotation of 180 degrees when decomposed.

from the node2d docs

solution here

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.