- Home /
Having four objects: ObjectA, CameraA, ObjectB and CameraB, how can I "imitate" rotation from CameraA to CameraB?
Hello! I am trying to apply a rotation of CameraA on CameraB. But taking into consideration Objects A and B. For example: If CameraA is looking at ObjectA, the CameraB should look at ObjectB. If CameraA is looking at 45 degrees to the left of Object A, the CameraB should look at 45 degrees to the left of Object B.
The ObjectA is identical to ObjectB. But their rotation is different.
Anyone have any suggestions?
Thanks.
Answer by ImpOfThePerverse · May 19, 2018 at 03:54 PM
This thread has an answer for how to get a relative rotation. https://answers.unity.com/questions/35541/problem-finding-relative-rotation-from-one-quatern.html Applying it to your situation:
Quaternion relativeRotation = Quaternion.Inverse(ObjectA.transform.rotation) * CameraA.transform.rotation;
CameraB.transform.rotation = ObjectB.transform.rotation * relativeRotation;
If you need to update the position too, I'm pretty sure it's:
Vector3 relativePosition = Quaternion.Inverse(ObjectA.tranform.rotation) * (CameraA.transform.position - ObjectA.transform.position);
CameraB.transform.position = ObjectB.transform.position + ObjectB.transform.rotation * relativePosition;
Thanks. I had seen the relative rotation answer. But I had not been able to do it work. I had reversed the order of "multiplication". Now, it works fine.
Tank you so much.
Your answer
Follow this Question
Related Questions
allows users to view 360º content without a VR headset 0 Answers
Problem restoring proper camera rotation 1 Answer
How to align an object's rotation to another GameObject's rotation (without parenting the Objects) 1 Answer
Orbit cam and Rigidbodies aiming 0 Answers
Workaround for Quaternion.eulerAngles 360 Degree Limit? 1 Answer