How it works...

In this recipe, we are using a Quaternion.LookRotation() method that creates a rotation, which works the same way as we would use the Transform.LookAt() function. It is applied to the head bone's transform. Our character's rig and all its bones are standard transforms in Unity. We can modify their rotation or position as we would with other game objects, but we need to do it in the LateUpdate() function because all the animations have to be evaluated first. We cannot modify any of the bones' transforms in the Update() function because all our modifications would be overwritten by the animations.

The Quaternion.LookRotation() function creates a rotation that makes a transform forward axis point to the desired direction. In most cases, the head bone's forward axis doesn't match the face of the character; thus, we need to apply an additional rotation. To do so, we use the public Vector3 additionalRotation variable.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.173.53