How do I rotate a target object around axis A by how much a different object is rotated around axis B?

You can get the steering wheel’s y rotation with Quaternion.eulerAngles and getting the y component:

float rotateAngle = stairing.transform.localRotation.eulerAngles.y; 

You can set the mirror’s localRotation to only rotate by rotateAngle around the Z axis by calling Quaternion.Euler with a forward vector whose length is the angle you’d like to rotate:

mirror.transform.localRotation = Quaternion.Euler(Vector3.forward * rotateAngle);

In your case, combining them might look like this:

void Update()
{
    float rotateAngle = stairing.transform.localRotation.eulerAngles.y;
    mirror.transform.localRotation = Quaternion.Euler(Vector3.forward * rotateAngle );    
}

Leave a Comment