# Making an objects y Rotation match another objects Z

Hi! I’ve been trying to figure this out for a few days now with no real progress.

I have an object that rotates on the Y axis. It has a child that billboards at the camera, and that object has a child that I need to rotate on it’s Z axis.

Main>BillBoard>RotationObject

I want the Z of this RotationObject child to match the Main parent’s Y, but keep it’s x and y axis at 0.

But I just can’t seem to get it to work. When it comes to Quaternions, I tend to get confused rather quickly. I’ve been trying LookAt and Euler Angles stuff, but it always gives me the wrong results.

Any help would be greatly appreciated, as I’m starting to lose a ton of time to this small feature.

Heres the Billboard script the second object is using:

```````void Update ()
{
Vector3 v = Camera.main.transform.position - transform.position;
v.y = v.z = 0.0f;
transform.LookAt(Camera.main.transform.position - v);
}
``````

`

If you’re thinking in terms of rotation around the X, Y, and Z axes, that refers to euler angles.

Many people find it easier to use euler angles, but they’re not quite the same thing as quaternions (which Unity uses internally). Luckily, Unity provides some code hooks for going back and forth between the two:

Each GameObject has a transform component, which keeps track of its position, rotation, and scale, among other things.

So, we need to do three things:

• Grab the target’s rotation, in euler angles
• Transpose the angles to use (0,0,y)
• Assign new rotation to our object

Something like the following JavaScript would do what you’re looking for:

``````var target : Transform; //set this in the inspector!

function Update() {
var euler = target.rotation.eulerAngles;   //get target's rotation
var rot = Quaternion.Euler(0, 0, euler.y); //transpose values
transform.rotation = rot;                  //set my rotation
}
``````

I have an Aircraft flying along (SampleAssets from Unity), and
I have used your calculations, but, in order to have the camera change,
according to the Aircrafts rotation, I have had to do the following:

`
void Update()

{

``````var euler = Aircraft.transform.rotation.eulerAngles;

var rot = Quaternion.Euler( 90, 0, <b>-(euler.y))</b>;

``````

}

`
The logic here is:
The RadarCamera (empty GameObject), with a Camera attached to it,
is set up using the normal X, Y, and Z axis’.
So, then the camera is rotated down 90 degrees, so
now the Z axis is pointing down, and the Y axis is pointing forward,
so by rotating the Z axis in the reverse, solves my Radar issue.
Thanks so much for YOUR logic.!!!