Rotate an object respectively to other object's rotation on z-axis

Say, we have obj1 and obj2.

I want rotation of obj2 around it’s transform.forward to EQUAL the obj1.transform.rotation.z. HOW should i do it?

obj2.transform.rotation.z = obj1.transform.rotation.z;

doesnt work fine if obj2 is already rotated around its x, y and z axis.

The manual says that reading out a single eulerAngle isn’t reliable (even if it did sometimes work.)

So they can both face any direction, but the “roll” should be as equal as possible? Could abuse LookAt to copy #1’s UP into #2. Will “flip” when obj2 is facing opposite obj1, but might still look nice:

Transform tr2 = obj2.transform;
Vector3 justAhead = tr2.position + tr2.forward;
obj12.transform.LookAt( justAhead,  obj2.transform.up );

The LookAt won’t change the way you face, but will “roll” obj2 to try to align its up with obj1’s up. Alternately, if you’re already using a lookAt, toss in the alternate up there.

I figured it out. It’s damn simple :slight_smile:

obj2.transform.localEulerAngles.z = obj1.transform.localEulerAngles.z;