0 votes

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
asked Jul 24 in Engine by SlavJuan (14 points)
edited Jul 24 by SlavJuan

1 Answer

0 votes

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
answered Jul 24 by p7f (3,284 points)
edited Jul 24 by p7f

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

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

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

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?

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.

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.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.