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?

asked Jul 3, 2019 in Engine by ThreeSpark (88 points)

1 Answer

+1 vote

Use the built-in function look_at:

look_at(get_global_mouse_position())
answered Jul 4, 2019 by Dlean Jeans (3,873 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.