# Move the player smoothly from a list of vector2's

I am trying to find a way to move a player to a list of vector2’s one by one,
So that if the player is at position 0,0 and the first vector is 0,5 it will move to the position 0,5 before moving on to the second vector2 which might be something like 5,5 and so on.
I have been trying to find ways to do it over and over again but every time I do something and finally get rid of all errors the player just wont move…
Any idea how I should work on it to make it work, specific procedure, specific code?
Help would be greatly appreciated thank you
AliquidHacker

This took me way longer than expected due to some unexpected errors but here is the code I came up with, basically it finds your list of vector2’s and makes sure the player is at the same position as its previous vector2. Than it moves the player from its position to the next vector2 (Hense playerpos+1).
And so on until the vector2 is done, you will however get an error once all of the vector2’s are done, my time is limited at the moment so I didn’t make a fix for that, it is relatively easy and you should be able to fix it on your own. Anyway here is the code,
using UnityEngine;
using System.Collections;
using System.Collections.Generic;

``````public class GhostPlayer : MonoBehaviour {

public List<Vector2> playerMove;

public int numberOfMoves = 0;
public bool canMove = true;

void Update () {
if (this.transform.position.x == playerMove [numberOfMoves].x && this.transform.position.y == playerMove [numberOfMoves].y) {
canMove = true;
}

if(canMove) {
this.transform.position = Vector2.MoveTowards(this.transform.position, playerMove [numberOfMoves+1], 6 * Time.deltaTime);
if (this.transform.position.x == playerMove [numberOfMoves+1].x && this.transform.position.y == playerMove [numberOfMoves+1].y) {
canMove = false;
numberOfMoves++;
}
}
}
}
``````

the reason why I made a bool labeled can move is because if I left the command to be executed once the player would move halfway and the code wouldn’t continue.
I am not saying that my way is the most efficent way to do this but I hope its good enough for what you are looking for,
NightLucidity