Godot Version
4.2 Stable
Question
I’m making a game, using 3D but with a 2D view and want the gun to aim where the mouse cursor is, I’m casting a ray from the camera using event EventInputMouseMotion and the look_at() function, however, the gun doesn’t really follow the cursor and depending on the mouse position it will actually aim the wrong way.
What am I doing wrong?
The code that rotates the weapon:
var from = camera.project_ray_origin(event.position)
var to = from + camera.project_ray_normal(event.position) * ray_length
gun.look_at(Vector3.UP, to)
A look at what it does: