I am trying to get a line of spheres to move around but all i get is the first sphere to move and get the rest to follow as one instead of building a sort of a train of spheres. Any idea how to alter the code to get it right? In the code bellow i get the first pbject in listBalls to move nicely along the Bezier curve but the rest move as one and overlap with the first sphere too.
void Update()
{
t += Time.deltaTime * 0.2f;
ballPosition = Mathf.Pow(1 - t, 3) * p0 + 3 * Mathf.Pow(1 - t, 2) * t * p1 + 3 * (1 - t) * Mathf.Pow(t, 2) * p2 + Mathf.Pow(t, 3) * p3;
positions.Add(ballPosition);
listBalls[0].transform.position = positions[j];
for (i = 1; i < listBalls.Count; i++)
{
Transform ball = listBalls[i].transform;
Transform nextBall = listBalls[i - 1].transform;
if ((ball.position - nextBall.position).magnitude > 1f)
{
ball.position = positions[j];
}
}
j++;
Feels like it should be something easy, setting the N-1 balls to same position as the first ball must be wrong. I tried setting them at positions[j-2] but it didn't work either.
Edit: the Spheres should start rolling left to right one after the other eventually all 10 should be on the screen and when they reach P3 they should restarting the rolling.
- listBalls is the List with 10 spheres
- positions is the List with 50 Vector3 positions along the curve.
[![enter code here][2]][2]