This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I cant seem to figure out how to make this work

if get_global_mouse_position() <= self.position:
    $Sprite.flip_h == true
    $Sprite.flip_h == false
in Engine by (20 points)
edited by

1 Answer

0 votes

Try with global position:

if get_global_mouse_position() <= self.global_position:
    $Sprite.flip_h = true
    $Sprite.flip_h = false
by (3,505 points)
edited by

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.