- Home /
Unity rotation
Quaternion targetRotation = Quaternion.LookRotation(path.lookPoints[pathIndex] - transform.position);
transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, turnSpeed);
My piece of code is above. I am following a tutorial for a 3d pathfinding script, but I use it for a 2d game. Everything worked fine until now, but I got in some mathematical trouble, i think it is good to say. My gameobjects are places into a xy axis coordinate. I want to face them one toward another, so I tried using Quaternion.LookRotation, and it changed the rotation on x and y axis but apparently i need to rotate it on z axis (for no reason known to me). Any help?
path.lookPoints[pathIndex] is a vector 3 with the target coordonates
What do you personally consider the "forward" axis in your 2D game?
Answer by Ady_M · Jan 11, 2019 at 11:29 PM
You might want to consider positioning and rotating the camera so that the built-in functions (transform.LookAt, Quaternion.LookRotation, etc.) work without having to make adjustments.
It would help if the camera's forward axis is aligned with the world x-axis.