How to make a 3D object look at the mouse and lock other rotation axis?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By bodicpen

I’m making a 3D game but the camera is fixed to make it look like an isometric game, like how Project Zomboid’s camera is set up.

I have a 3D object which is just a simple cube sitting on a 3D Mesh (Supposed to be my player). I’ve used the following code to make it look at the mouse:

func _physics_process(delta):
var from = $Camera.project_ray_origin(get_viewport().get_mouse_position())
var to = from + $Camera.project_ray_normal(get_viewport().get_mouse_position())
$Player.look_at(to, from)

all is well except that the whole cube is rotating in all axis, I just want it to rotate on its y axis, essentially locking the x and z axis to zero. How can this be achieved? Thank you!

I’m having the same exact issue. Did you find a solution??

joseignacio1 | 2020-08-26 05:00