# Move an object through a set of positions

Hi,

I am trying to figure out how I can make an object move through a set of positions…

I have an object and a set of position, like 5 different positions, for example. So, I would like to do my object go from point 1 to point 2, from point 2 to point 3, from point 3 to point 4 and, finally, from point 4 to point 5, smoothly.

I read answers like this one Move an object through a set of positions - Questions & Answers - Unity Discussions and this one Make an object move from Point A to Point B then back to Point A repeating - Questions & Answers - Unity Discussions, particularly. I’ve implemented this last one, but nothing happens. This is my code:

``````	for(int i = 0; i < number_pos-1; i++)
{
StartCoroutine(moveB(positions*, positions[i+1], 2.0f));*
``````

_ //StartCoroutine(moveA(positions*, positions[i+1]);_
_
}_
_
}*_

* IEnumerator moveA (Vector3 pointA, Vector3 pointB)*
* {*
_ transform.position = Vector3.Lerp(pointA, pointB, Time.time * smooth);_
* yield break;*
* }*

* IEnumerator moveB (Vector3 pointA, Vector3 pointB, float time)*
* {*
* float i = 0.0f;*
* float rate = 1.0f/time;*
* while (i < 1.0) {*
_ i += Time.deltaTime * rate;_
* transform.position = Vector3.Lerp(pointA, pointB, i);*
* yield break;*
* }*
* }*
Thanks for any help!

You want to use

`````` yield return null;
``````

not yield break which just stops it immediately.

But you’ve also got a problem in the outer loop which should also be a coroutine and you should be doing

``````  yield return StartCoroutine(moveB...
``````

Hi, I could do this with the code bellow:

``````IEnumerator Move()
{
for(int i = 0; i < number_pos; i ++)
{
currentPosition = i;
yield return new WaitForSeconds(1f);
}
}

void FixedUpdate()
{
if (currentPosition == -1)
{
return;
}

transform.position = Vector3.Lerp(transform.position, positions[currentPosition], Time.deltaTime * 10);
}
``````

After this, following a friend tip, I start to “play” with AniMate (http://wiki.unity3d.com/index.php?title=AniMate) to do more complex animation via script. (: