0
\$\begingroup\$

I have a DoorSprite with an Animator component which I animate by rotating it by 90 degrees (makes the door look like opening around a hinge).

The parent, Door, is empty and only holds the DoorSprite child GO.

Structure

To achieve the hinge effect, I've set the pivot of the door sprite to the left side. I now want to rotate the parent but the problem is that all the children inside the parent rotate too, but not by the parent's pivot (which is center), but by their pivot.

This is the Door parent before rotation:

before

When I rotate the Door parent by 90 degrees, this is what I want to achieve:

desired

However, this is what actually happens (the sprite pivot (hinge) is marked with the arrow):

actual

How can I rotate everything by the pivot in the center, regardless of child pivots?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

I have managed to solve this issue by rotating the door parent around the center point of the coordinates it's sitting in. In my case, if the door was on (0,0), but it's actual center was on (0.5, 0.5), then I'd want to rotate around (0.5, 0.5).

For me, that meant that I just want to rotate the object around it's position + an offset that represents it's actual center.

var offset = new Vector3(0.5f, 0.5f, 0);
door._doorGameObject.transform.RotateAround(door.Node + offset, Vector3.forward, 90);

Doing it this way, the children no longer rotated around their own axis and I could properly rotate the base of the door as intended.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .