I’m trying to rotate a GameObject that consists of several cubes around y-axis of its center of gravity using a script (Picture 1). However, it’s rotating around its pivot point when I use transform.Rotate() (Picture 2). Is there a way to make it rotate around the point in Picture 1?
You probably just want to change the “pivot” of the parent object. Which means change the parent object’s position and adjust the child objects’ positions accordingly:
public void PivotTo(Vector3 position)
Vector3 offset = transform.position - position;
foreach (Transform child in transform)
child.transform.position += offset;
transform.position = position;
So can just calculate your center of mass or whatever position and tell the parent object to “pivot” to there.