How do I make my platformer character face towards the side that cursor is located?

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

like in this game

:bust_in_silhouette: Reply From: jgodfrey

If you just want the character to face left or right based on which side of the character the mouse cursor is on, that’s pretty simple. Here’s one example:

func _process(delta):
    $Sprite.flip_v = get_global_mouse_position().x < $Sprite.position.x

In this case, I’m just setting a sprite’s flip_v propery to either true or false based on whether the mouse cursor is on the left or right of the sprite.

Note, the above code assumes the sprite faces right by default…