- Home /
Getting a 2d Sprite to move over time to an Array
I'm trying to get a 2d sprite to move through an array using Vector2.Lerp, but it jumps to a completely different location:
public Vector2[] place;
void Awake(){
place[0].x = 100;
place[0].y = 100;
place[1].x = 100;
place[1].y = 0;
}
public void MoveMe(){
transform.position = Vector2.Lerp(place[0], place[1],Time.time);
}
Can anyone tell me why or offer a solution?
As per Fattie try transform.position = Vector2.Lerp(transform.position, place[1],Time.time);
calling $$anonymous$$ove$$anonymous$$e in your update
Answer by robhuhn · Oct 26, 2012 at 03:50 PM
That answer could help to use Lerp: http://answers.unity3d.com/questions/337145/help-with-lerp-1.html
Ah, yes. Now I feel stupid. Time.time isn't going to do anything as the third variable is clamped to 1. as per the linked thread, the last variable should start at zero, and increment over time to 1. The amount it increments per second will control the speed at which the object will move.