Change self.position
to self.global_position
and then I think it should work. You can also optimize your code a little, by using else
rather than elif
:
extends Sprite
onready var sprite = $Weapon
func _physics_process(delta):
if get_global_mouse_position().x < self.global_position.x:
sprite.flip_h = false
else:
sprite.flip_h = true
position
gets the position of the node relative to its parent (local space), while global_position
gets the position relative to origin (global space).