I need to make an object rotate the exact same way as its parent object, how do I do this?
Maybe rotate the parent ?
I’m not sure to understand what you mean…
It should do that be default?
Or if you mean, you need two objects, with separate pivots, to rotate the same way. Well then you gotta script that I’m pretty sure.
var parentTransform : Transform;
function Update()
{
transform.rotation.x = parentTransform.transform.rotation.x;
//copy paste above line for each needed axis
}
put that on your child object, then drag the parent object into it’s transform slot
Unity has a built-in system for parenting and object hierarchies. You can parent objects to each other in the editor window by dragging one game object on top of another one in the hierarchy window. Child objects will then inherit all position, orientation and scale values from their parents.
Is this what you want, or did I misunderstand?
Edit: Oh wait, if you want objects to just inherit rotation, but not position and scale, you indeed need to make your own solution. Eem’s script will work nicely.
Edit2: Eric is right, it should be something like:
transform.rotation = targetTransform.rotation;
… unless you want to calculate W for every XYZ yourself, or something.
Transform.rotation is a quaternion, so rotation.x isn’t what you might think it is. Just use the whole thing, not any of the components.
–Eric
Thanks a lot guys.