0 votes

So, my player is holding a weapon that points towards the mouse, but it looks crooked when it goes 180 degrees, so is there any way I can flip it once it reaches (-)90 degrees?

Script:

``````extends Sprite

#var gunRotation = rotation_degrees(0, 0)

func _process(delta):
var mpos = get_global_mouse_position()
look_at(mpos)
``````
in Engine

you can flip the sprite vertically once it passes ±90 degrees angle(might need to set it to different angle because godot's angles are kinda weird) using `get_rot()` or `rotation` if you are on godot 3 branch and flipping accordingly

## 1 Answer

0 votes

Yes, the angle is found in the vector between the cursor and the gun tip (or aim origin).

`var ang = (get_global_mouse_position() - gun_tip.get_global_pos()).angle()`

`print(rad2deg(ang))`

Just make sure your angles match Godot, or do a conversion on your angles.

0 points down, 180 and -180 point up.

From 0 heading clockwise will cover 0 to -PI (-180), and the counter-clockwise direction covers 0 to +PI (+180).

by (5,252 points)

I've tried my best, but I get this result: https://gyazo.com/43a0d74d75707281ecc27a60f2411688

Here's the code;

``````extends Sprite

func _process(delta):
var mpos = get_global_mouse_position()
var ang = (get_global_mouse_position() - self.get_global_position()).angle()

look_at(mpos)

print(rad2deg(ang))

if (ang >= 90):
#elf.set_flip_h(false)
self.set_flip_v(false)
elif (ang >= -90):
self.set_flip_h(true)
self.set_flip_v(true)
``````