flip_h when mouse is left of the player *FIXED*

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

I cant seem to figure out how to make this work

look_at(get_global_mouse_position())
if get_global_mouse_position() <= self.position:
	$Sprite.flip_h == true
else:
	$Sprite.flip_h == false
:bust_in_silhouette: Reply From: p7f

Try with global position:

look_at(get_global_mouse_position())
if get_global_mouse_position() <= self.global_position:
    $Sprite.flip_h = true
else:
    $Sprite.flip_h = false

Sorry for not being clear but also the lines that set flip_h true/false have no effect on the code.
Though global_position helped to get some kind of signal to execute the if statement.

SlavJuan | 2020-07-24 18:50

Check that you used == while trying to set the variables… it should be =

p7f | 2020-07-24 19:03

I’m trying to make the character flip to the left when he is walking left and flip to the right when he is walking right and it says this “invalid set index ‘flip_h’ (on base: ‘null instance’) with value of type ‘bool’.” Please could you help I’ve been stuck on this for a few hours and I don’t know how to fix it. This is the script I am using:

if vel.x < 0:
	sprite.flip_h = true
elif vel.x > 0: 
	 sprite.flip_h = true

kokickosta | 2020-09-01 00:07

Thats probably because sprite is not a valid reference to the node… can you show an image of the tree, and the portion of the code when you declared sprite?

p7f | 2020-09-01 00:09

I’m sorry but I am new to programming so I don’t really get what you mean. I don’t have a tree. I only have a Tile and a Character.

kokickosta | 2020-09-01 17:24

The tree is the hierarchy of nodes you see in the scene dock. Im guessing you are trying to access sprite, but the path to the node that actually holds that sprite is wrong.

p7f | 2020-09-01 18:04