# Multiple GameObjects moving in circular path

Hello guys, Iam making a 2d game in which i want to make some kind of “ring” composed of game objects that spin around the same centre and with the same radius…

(Watch this video I want to do the same that is done there with the apples).

The issue is that the script I ve done always set the same transform to all the gameObjects, so all of them are always ‘aligned’ and you will only see one of them . It doesn’t matter if they were originally positioned apart from each other, once the script runs they start spinning but always in the same position…

Here’s the code:

``````using UnityEngine;
using System.Collections;

public class CircularMovement : MonoBehaviour {

public Transform center;
public float angle =0;
public float period = 6f;

// Update is called once per frame
void Update () {
angle += period*Time.deltaTime;
float x = Mathf.Cos(angle)*radius + center.transform.position.x; //x=cos(angle)*R+a;
float y = Mathf.Sin(angle)*radius + center.transform.position.y; //y=sin(angle)*R+b;
this.gameObject.transform.position = new Vector2 (x,y);
}
}
``````

Thanks!!

Looking at the video, the apples keep their orientation as they rotate. That implies they are using position like you are doing in your code instead of the numerous other solutions for rotating around something. Here is a bit of code using a vector that implements what I see in the video. Note that I’ve removed ‘radius’, and simply use the starting position of the object with respect to the center to calculate the radius.

``````using UnityEngine;
using System.Collections;

public class CircularMovement : MonoBehaviour  {

public Transform center;
public float degreesPerSecond = -65.0f;

private Vector3 v;

void Start() {
v = transform.position - center.position;
}

void Update () {
v = Quaternion.AngleAxis (degreesPerSecond * Time.deltaTime, Vector3.forward) * v;
transform.position = center.position + v;
}
}
``````