How to make the character flip according to the position of the mous

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

I occupy the character to turn vertically only according to the position of the mouse, so if the mouse is below the player it does not detect it, it only detects when it is to the right or to the left

I tried to make an animation according to the degrees of rotation and it went from a number of degrees to return to the stated amount but it gives many failures

:bust_in_silhouette: Reply From: IHate

If you want to flip a sprite and its pivot is centred you could use something like:

#Horizontal flip
if get_global_mouse_position().x > position.x && is_flipped_h() == false:
	set_flip_h(true)

elif get_global_mouse_position().x < position.x && is_flipped_h() == true:
	set_flip_h(false)

#Vertical flip
if get_global_mouse_position().y > position.y && is_flipped_v() == false:
	set_flip_v(true)
	
elif get_global_mouse_position().y < position.y && is_flipped_v() == true:
	set_flip_v(false)

In this example the character should be facing left if it’s a profile sprite.

If you want to gradually rotate you sprite looking at your mouse you could use the look_at() function in combination with get_global_mouse_position(). If you want to use this move the pivot of your sprite to where the rotation should occur.

For example:
If I have the sprite of an arrow and I want it to point towards the mouse I have to move the pivot of the arrow sprite to the base of the arrow.

Ready thanks bro, it helped me a lot

elrico26 | 2020-10-16 17:17

There is an error which says “The method “is_flipped_h” isn’t declared in the current class”

NARZ | 2021-03-16 19:32

Make sure you are using an sprite or an animatedsprite and that your script is extending one of these classes

IHate | 2021-03-18 15:59