Flip the scale of a child node independent of the parent

Godot Version

4.3

Question

I’m trying to flip my character 2 directions, left and right. However, i have a lot of different stacked sprites/etc, so I’ve been just switching the scale of the whole player instead -

direction = Input.get_vector("ui_left", "ui_right","ui_up", "ui_down")
var direction:Vector2 = Vector2.ZERO:
	set(new_dir):
		if(new_dir.x > 0):
			scale.y = 1
			rotation_degrees = 0
		if(new_dir.x < 0):
			scale.y = -1
			rotation_degrees = 180
	direction = new_dir

However, since I need the player’s global rotation for other aspects of my game, setting it to 180 whenever I’m looking left is a lot to keep working around.

I’d like to only flip the scale of the sprites on my character – specifically, I want to only flip this child scene branch of my Player scene -
image

I want to do the exact same thing as ^ above, but using the AnimSprite’s scale –

        if(new_dir.x > 0):
			$AnimSprite.scale.y = 1
			$AnimSprite.rotation_degrees = 0
		if(new_dir.x < 0):
			$AnimSprite.scale.y = -1
			$AnimSprite.rotation_degrees = 180

When I try this, the scale constantly gets overwritten when I move left, so it never actually flips. I can see the scale is always trying to revert to the parent’s base scale of 1, instantly after I set it to -1. Is there a way to set the scale of a child node, without it immediately reverting to the scale of the parent node?

I want to flip things like Marker2D’s too in the scene tree (which regularly change per animation frame), so calling flip_h on every sprite individually doesn’t really serve my purpose. If anyone has a solution it’d be a huge help :pray:

(EDIT - if anyone is wondering why I’m using negative scale.y and not x, this messed me up for a while so I’m just being explicit–)

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.

I didn’t tried it for myself but if you check the top level option on the Transform in Inspector, it will said that your node will stop to inherit it’s transformation from parent.
image

1 Like

I’d suggest looking into RemoteTransform2D

1 Like

Both of these ideas have been super helpful, thank you so much :smile:

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