0 votes

I am trying to get an Area2D to rotate towards the mouse. Instead of rotating towards the mouse, it splits into two (both are, i think, 50% transparent) and rotates in two different directions instead of just rotating towards the mouse. If I use getviewport().getmouseposition() or getglobalmouseposition() instead of getlocalmouse_position(), it rotates when the mouse moves, but not towards the mouse, and not as fast as the mouse moves.
Here is the related code:

var mpos

func _process(delta):
    var mpos = get_local_mouse_position()
    rotation = mpos.angle()

Could someone please help me?

in Engine by (122 points)

1 Answer

+1 vote

Use the built-in function look_at:

look_at(get_global_mouse_position())
by (4,005 points)
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 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 webmaster@godotengine.org with your username.