- Home /
Move Objects arranged in Circle Forward
Hey Guys,
i have a strange problem. Lets say i have cubes arranged in a circle around a sphere. And i want to move each of them away from the sphere, with the same distance. How can i accomplish this?
Ideally, I have to realize this without having to attach a script to each of the cubes.
Would be awesome if anybody could help me.
Thanks in advance.
The basic calculation is:
box.transform.position = (box.transform.position - sphere.transform.position).normalized * dist + sphere.transform.position;
If you had your boxes in an array (tagged the same and use GameObject.FindGameObjectsWithTag() for example), you could cycle through your array and apply this calculation to each box. 'dist' is the distance you want the boxes from the center of the sphere.
Answer by moocho · Sep 08, 2014 at 09:03 AM
Thank you! I tried your solution and it works also. But in the meantime I had solved it like this.
cube.transform.position -= cube.transform.forward * distance;
which was right there in the documentation... i felt stupid for asking.