- Home /
LookRotation over a local axis
Hi, I'd like to make a clank rotating towards a controller cube moved by the player. The clank rotates around its local y axis while the player moves his controller cube. I just set the x and z rotation to 0 to keep only the y rotation. The trick is that I want the clank to rotate on x the parent platform on which the player and the clank are. It works well until the up vector of the clank (and the platform), which initially is the y axis, becomes the z axis. At this moment, the lookRotation looks like being stuck, unable to keep track of my cube controller correctly. Here's my code :
Vector3 relativePosition = cubeController.transform.position - turningObject.transform.position;
Vector3 lookRotation = Quaternion.LookRotation(relativePosition, turningObject.transform.up).eulerAngles;
lookRotation.x = lookRotation.z = 0;
Quaternion newRotationQuat = Quaternion.Euler(lookRotation);
turningObject.transform.localRotation = newRotationQuat;
Version Unity2017.1.1f1
[Explanation Gif][1]
(Sorry if the question has already been asked) [1]: http://yvanricher.lescigales.org/webPosts/LookRotation.gif
Comment
Your answer