Can anyone help me make a node point to the mouse position?

Godot Version

Godot 4.2.1

Question

I need to make a node point in the direction of the mouse, I searched here and none of the answers worked, and I’m sorry if this is very basic, I started using Godot literally 3 days ago.

capt1

The script:

extends Sprite2D

func _ready():
pass

func _process(delta):
apontar()
pass

func apontar() → void:
var pos = get_local_mouse_position () - position
look_at(pos)

I suspect it’s just misunderstanding what look_at does. Based on this from the docs:

void look_at ( Vector2 point )

Rotates the node so it points towards the point, which is expected to use global coordinates.

The point you pass to it should be the point you want it to look at. Your instead passing it a direction vector. It probably just needs to be:

look_at(get_global_mouse_position()).

If you need to offset it at all, it would probably be relative to the camera, not the node your trying to track?

1 Like

IT WORKED!!! Thank you very much!!!

1 Like