- Home /
Rotate transform without rotation the children
I need a function, that just rotates the parent of a hierarchy and not its children. Is there a function that could do that? Else, would it be a good idea, to put all childs into an array, then detach the children, rotate the parent and then put them back into it?
As a little side note: Just one children shouldn't rotate with the parent.
Answer by almo · Jul 20, 2011 at 01:54 PM
I am questioning if you really want the children on the parent if you need to rotate the parent independently.
Maybe attach the children to another object instead, and have that object update its position to be the same as the parent. That way the children update to the new object's position, which updates to the "parent"'s position. But when the "parent" rotates, the others don't.
He was probably hoping there was an easy way to lock the rotation since if you set it as a child, Unity automatically translates the transform for you to keep it in sync with it's parent.
Otherwise, you have to set up a 'target' object that you constantly move to the player object, and set the camera as a child of that. It's just messier.
Also, taking a total stab in the dark here... wouldn't unity's built-in transform updates probably be more performant than any attached to the object with a script? I'm not sure this will ever be a significant amount of processing... but I'm curious anyway.
To clarify, attaching the camera to a sibling of the target, and moving the sibling to the same transform as the target, seems to be the best result.
You can do some funky stuff with resetting the rotation, etc. but it seems to cause some really strange and terrible jerky behaviour you don't want.