- Home /
Make an object mimic the rotation of another one according to their orientations
Hello, i'm looking for a way to apply the rotation of object A to object B knowing A and B have different orientations. For example, if A rotates 90 degrees on A's x axis, i want object B to rotate 90 degrees on B's x axis. I found a way to do the same thing with position, using the methods : " transform.InverseTransformDirection" and "transform.TransformDirection" but i can't seem to find a way to do it for rotation. Any help would be really appreciated !
Answer by oTaijjo · Dec 05, 2019 at 12:35 PM
You could try the transform.Rotate() method and rotate both with the same value, i.e.
Vector3 eulerAngles = Vector3.up * 90f;
a.transform.Rotate(eulerAngles);
b.transform.Rotate(eulerAngles);
Hope that helps! :)
Answer by Claoudy · Dec 05, 2019 at 01:56 PM
Thank you for your answer ! Sorry if it wasn't clear, I don't have any control over object A. That's why i'm trying to get the rotation of A between 2 frames and apply it to B. I tried doing it with euler angles but it doesn't return the exact same rotation, something close though. It might be because of the gimbal lock, i don't know much about the subject. Following is the code I call on my update method :
rotationA1 = rotationA2;
rotationA2=objectA.transform.eulerAngles;
rotationB1 = rotationB2;
var rotationDeltaA2A1 = rotationA2 - rotationA1;
rotationB2.x += rotationDeltaA2A1.x;
rotationB2.y += rotationDeltaA2A1.y;
rotationB2.z += rotationDeltaA2A1.z;
objectB.transform.rotation=Quaternion.Euler(rotationB2);
Your answer
Follow this Question
Related Questions
How to ROTATE an object without slowing the ends (lerp) 3 Answers
Smooth transform position and rotation 1 Answer
Rotation not going past 180? 2 Answers
why update function doesn't work on the transform.Rotate function 0 Answers
Following another object's position/rotation like parent/child relationship? 4 Answers