- Home /
Question by
PizzaGuy213 · Aug 05, 2018 at 12:23 AM ·
quaternionlookatfromtorotation
Get LookAt to work correctly with adjustment for rotated pivot
Hi!
I've been having problems getting LookAt to work for object that have a non-standard pivot.
In this example I'm using LookAt to rotate the eyes (left picture), which works fine, since the pivot's local Forward for the eyes is the same as Forward in World space.
For the head however (right picture), the local pivot is rotated due to the way the skeleton is made, which results in non-accurate, almost excorcist-like behavior when using LookAt.
I've been trying to adjust the rotation after using LookAt, but haven't gotten it to work. Can someone help me out?
Code I have now:
Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
float midpoint = (head.transform.position - Camera.main.transform.position).magnitude * 0.5f;
head.transform.LookAt(mouseRay.origin + mouseRay.direction * midpoint);
head.transform.rotation = Quaternion.FromToRotation(Vector3.up, Vector3.forward) * head.transform.rotation;
Thanks in advance!
differentpivots.jpg
(280.7 kB)
Comment