Hi,
I have 5 gameobjects that are arranged in a circle. Each gameobject is rotated in the world-z by 72 degrees so that they all orient towards the center of the circle (like the markings on a clock face).
See Image
I want those items to converge on the center of the circle, and then move back out again.
I really thought this would be simple, but have been unable to get it to work trying various methods. This is my latest failure. This script sits on an empty GameObject called PillarController.
public List<GameObject> Pillars = new List<GameObject>();
public float distance;
public float MoveSpeed;
void Update()
{
foreach (var pillar in Pillars)
{
var localPos = pillar.transform.localPosition;
var newY = Mathf.PingPong(MoveSpeed * Time.time, distance) - (distance / 2);
Debug.Log(newY);
pillar.transform.Translate(localPos.x, newY,localPos.z, Space.Self);
}
}
Each capsule is parented to an empty game object that is at (0,0,0). The capsules are then offset on their Y axis (by 2 units in this case). The parent game objects are rotated in their z-axis by 72 degrees.
See Image
When this runs, a few of the capsules ping-pong in the global Y axis, and a couple just find it all too much and shoot off into space, never to be seen again, which quite frankly seems like a good idea at the moment.
What the flip am I doing wrong? Example attached as package.
Thanks
Mick
8121416–1052642–PingPong.unitypackage (9.62 KB)