Make child unaffected by parents rotation?

I have a ball with a 2D circle collider and I need to attach a face to this ball but I want the face to be unaffected by the balls rotation. I’ve tried using the “Kinematic” option on a rigidbody and tried to freeze rotation too but with no luck.

Is this possible? Is it possible to have a child be unaffected by its parents rotation? If so, how?

I’ve done this by resetting the child object’s rotation to its initial value in Update()…this is not the best solution if you need to do this for a lot of objects.

Outside of this, about the only thing you can do is move the child object (if possible)

It’s only 1 object that will have this at any given time (the player).
But I suppose that I could also give the “face” a player reference and have it follow the player with “Update()”. But wouldn’t that mean the face is already lacking behind a bit?

Yes, however, you are not likely to notice it

Use LateUpdate instead.

A better solution would be to unparent it, and set its position in LateUpdate to match its “fake parent”, rather than resetting transform.rotation every frame.

3 Likes

Why would this be a better solution, is resetting the local rotation faster than setting the global transform position?

I haven’t done any testing, but judging by this discussion I would have expected the opposite to be the case.

In the context of that discussion: unparenting and setting position would be one “step” more efficient than setting rotation.

In order to make the rotation fixed, you must set it using transform.rotation rather than .localRotation. When you do, it must “crawl” up the hierarchy to invert the rotations of each parent object, before applying the rotation. At minimum, if the ball has no parents, it must do 1 such transformation.

If the face has no parents, then setting .position is the same as setting .localPosition. You must get the ball’s transform.position, but if the ball has no parents, then it too would be the same as .localPosition. Thus, at minimum, if the ball has no parents, it must do 0 such transformations.

However, that’s an insignificant cost, and not really what I was referring to. My main though was with regards to non-uniform scale changes (which, for a cartoonish ball with a face, is not unreasonable): if it were a child of the ball, the face would be unpredictably skewed by rotations like that.

3 Likes

Thanks for all the responses! :slight_smile: