how to make object rotate in same angle

Hi I’m using rotatearound in scirpt to move object rotate around player
First there is only one object that rotates player
but when player level up, game add more object to rotate

I want this objects to rotate at the same angle

If there is 2 objects then angle between objects would be 180’
If there is 3 objects then angle between objects would be 120’ … etc

I’ve tried some method but dosen’t work well or it gets wrong when player moves
Is there any way to make objects rotate in same angle while moving?

Easiest way to spin a bunch of objects is to parent all the objects to a single invisible central GameObject, then rotate that central GameObject and all its children will orbit.

Since you want that to follow your player, parent that central object to your player as well!

Easiest way to distribute a bunch of objects evenly around a circle is to divide 360 by the object count, then use Quaternion.Euler() to produce rotated offsets.

Yeah, yeah, that second thing sounds hairy, but it’s not. Check it out:

int count = 7;  // change to suit

for (int i = 0; i < count; i++)
{
  // find equally-spaced angles around the circle (like pie slices)
  float angle = (360.0f * i) / count;

  // unrotated offset (I chose up by 2 units arbitrarily)
  Vector3 offset = Vector3.up * 2.0f;

  // produce a rotation around Z
  Quaternion rotation = Quaternion.Euler( 0, 0, angle);

  // rotate the offset
  Vector3 rotatedOffset = rotation * offset;

  // TODO now use rotatedOffset to set the transform.localPosition of each child object going around
}

All of the above is for X/Y display, eg 2D. Adjust Line 9 and Line 12 to suit other orientations, such as standing on the ground.

Here’s a more-specific case that also supports an arc width:

1 Like