3D Isometric top-down view, make character always rotate towards mouse position

Hello, I currently have a simple player in form of a capsule and a cube that sticks out of it to mark the front side.
159606-screenshot-4.png
I want the character to rotate ONLY ON THE Y AXIS towards the mouse position. So if I would put my mouse cursor the left of the character I would like him to rotate towards it on the y-axis (so basicly frozen on the x and z axis).
159609-screenshot-5.png

I have already tried multiple different codes from other posts but in most of them he also rotates towards it on the other x axis. (they used the .LookAt() method).

Hi,

you could use .LookAt() and just save the value that the x-axis is at currently with Transform.EulerAngles.X then set the rotation on the x-axis back to that after using .LookAt(). Note that you can’t cust say Transform.EulerAngles.x = 10 or anything like that. You’d need to create a new vector3.

//Save current x rotation
float tempX = Transform.EulerAngles.x;

//Look where you need to
Transform.LookAt(Target);

//Reset the x rotation
Transform.EulerAngles = new vector3(tempX, Transform.EulerAngles.y, Transform.EulerAngles.z);

You might also want to save the z rotation in the same way. Also, I don’t know if you have the world space point that you want to look at yet (Target). If you don’t you could do a raycast to find it.

Another way to do this would be by doing the calculations yourself rather than using .LookAt() though this would involve some trig. You would need to use tangent and the difference in your player’s x and y and the mouse positions x and y. This isn’t super fun though because you’ve gotta figure a lot out for yourself, so as if saving the x works use that.