![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | bery |
so i am trying to make an object that points towards the mouse and orbits around a player . i found that i can simply use look_at(get_global_mouse_position()) to point it at the mouse and have the sprite2d offset so that it orbits around the player and it works. then i wanted to flip the object vertically if its rotated toward the left of the player. thats where the porblems start. i found that you can use get_angle_to in combination with rad_to_deg but the value that it gets seems wrong. sometimes it only sets a value while the mouse is moving and sometimes it makes it negativeand its always a value way below 0. Does anyone know why this is?
Can you share your code ? It would be easier to answer then.
Enfyna | 2023-07-08 19:49
here you go:
extends Sprite2D
var AngleToMouse
func _process(delta):
#find angle to mouse and flip if backwards
AngleToMouse = rad_to_deg(get_angle_to(get_global_mouse_position()))
if(AngleToMouse<0):
flip_v = true
else:
flip_v = false
print(AngleToMouse)
#look at mouse
look_at(get_global_mouse_position())
bery | 2023-07-08 21:03
Could you consider something like this :
func _process(_delta):
#look at mouse
look_at(get_global_mouse_position())
# do something with the node rotation
if(global_rotation_degrees < 0):
flip_v = true
else:
flip_v = false
look_at function rotates the node to the mouse so I dont think we need to calculate it again just look at the mouse first then you can do whatever you want with the rotation variable.
Enfyna | 2023-07-09 10:36