Changing the scale eventough i don't want

Godot Version

v4.3

Question

I am making a game where my 2d charachter follow my mouse and according to it, it is rotating the gun around himself. And when player point the mouse to its back i change the scale so it turns back. However, in game sometimes when it changes x scale it also changes y scale. How can i fix it?

Here is my code:

func gun_controller():
var mouse_position = get_global_mouse_position()
var gun_position = $Bob/Gun.global_position
var distance_vector = mouse_position - gun_position

if (distance_vector.angle() >= PI/2 or distance_vector.angle() <= -PI/2):
	if(scale_changed == false):
		$Bob.scale = Vector2(-1,1)
		scale_changed = true
	$Bob/Gun.rotation = PI - distance_vector.angle()
else:
	if(scale_changed):
		$Bob.scale = Vector2(1,1)
		scale_changed = false
	$Bob/Gun.rotation = distance_vector.angle()

You have to press this button:
grafik

1 Like