problem with get_scale()

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

I recently ran into a problem with the get_scale() function while writing some code to flip my character when moving left or right.

print(get_scale())
	if movement.x < 0 && get_scale()==Vector2(1,1):
	set_scale(Vector2(-1,1))
	print("facing left")
elif movement.x > 0 && get_scale()==Vector2(-1,1):
	set_scale(Vector2(1,1))
	print("facing right")

Whenever I start moving my character, it flips directions but never unflips. I decided to add the print statement to figure out what was going on, and in the beginning it prints out (1,1), but after flipping it prints (1,-1). This is quite strange since I never touch the y coordinate. Is this a bug? I don’t want to submit a bug report before making sure.

:bust_in_silhouette: Reply From: a_world_of_madness

From the Node2D docs:

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.

See the answer by Hyper Sonic