The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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 lookat(getglobalmouseposition()) 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 getangleto in combination with radtodeg 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?

Godot version 4
in Engine by (12 points)

Can you share your code ? It would be easier to answer then.

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()))
        flip_v = true
        flip_v = false
    #look at mouse

Could you consider something like this :

func _process(_delta): 
#look at mouse

# do something with the node rotation
if(global_rotation_degrees < 0):
    flip_v = true
    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.

Please log in or register to answer this question.

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.