# setting parent's rotation to a child's rotation

hey all,

im having issues with getting my character to move the way i need it to. the character is in two parts, the top and bottom. the bottom is the parent and the top is the child. the top rotates independently of the bottom (like a turret on a tank) and the whole character should move in a straight line until the player hits the space bar.

when the space bar is hit, i want the character to start moving in the direction the child(topHalf) is facing. here is how im trying to go about it:

``````if(Input.GetAxis ("Jump")){
transform.rotation.y = topHalf.transform.rotation.y;
}
``````

that works, but only if you’re trying to go forward. it seems like the greater the attempted change in direction the less it actually changes. (ie: if i want to make a slight turn it works, but if i want to go the opposite direction it just keeps going the same way)

any ideas on why this is happening and/or how i can get it working the way i need?

if i was unclear anywhere please let me know and i’ll try to explain it better.

jason

Yeah a bit unclear.

You’re trying to drive movement with a child, and not a parent? Or are you just trying to get the parent facing in the same direction as the child when you hit the space bar?

Maybe a diagram or an example project would help to figure out what you’re after.

thats it. i just got some help from the irc chat tho. my problem was that i wasn’t using euler angles.

``````transform.rotation.y = topHalf.transform.rotation.y;
``````

i need this:

``````transform.rotation.eulerAngles.y = topHalf.transform.rotation.eulerAngles.y;
``````

i guess my problem was/is that i don’t quite understand how/when quaternions should be used

so i am all set (for now). thank you quietus for the quick reply tho.

Whenever you’re manually setting a rotation to a specific degree angle (like, if you want your rotate-y to be 135 degrees), you should use euler angles. The ‘y’ component of a quaternion is not the same as the y rotation you see in the viewport.

If you want to set the orientation on ALL axes of one object to match another, using quaternions is fine - the trouble just comes in when you try to manually edit one axis or another. I don’t fully understand how a quaternion works myself, I just know its mysterious!

haha. yeah, youre the second person to tell me quaternions are some kind of voodoo magic. in this case, im content with not understanding fully. thanks for your help!

jason

My understanding of Quaternions is they stop Gimbal Lock, which is where a joint doesn’t know which way it is acing due to underlying rotation math and starts flipping or locking. Apparently XYZ rotations do odd things like if you rotate X then Y then Z 90 degrees and then rotate each -90 degrees Z - Y - X you do not end up back where you started. So quaternions do a bunch of trigonometry equations under the hood using exponents and squares so you can add or subtract angles coherently and end up where logic would seem to dictate you should be and not 90 degrees or other offset.

I think… i guess I am gonna learn today about them in code shortly as I write a RideObject equation that does not use reparenting.

Cheers
Bluster T