- Home /
Move continuously through array of Vectors
I need to move an object through an array of Vector3 coordinates smoothly. I've written similar code before, but moving from [a] to [b], then from [b] to [c] etc. means that for one frame the object is stationary. Does anybody know how to move through a list of Vectors continuously?
Unless you actually need to hit the vertices, the trick to not stopping is to figure out how far the calculated distance would take you past the next vertex and start the next line that far in.
That could work, but how could I calculate how much distance is actually covered per frame? Wouldn't it depend on framerate?
You define a rate of movement as units per second. Then at each frame, you multiply it by Time.deltaTime;
dist = speed * Time.deltaTime;
So dist is how far you will travel. If that distance is more than is left in the current line, you use the remainder starting from the next vertex.
I think I follow. On each frame of this movement we compare distance to the target, and if the distance to target is less than or equal to 'dist', we set the new target as the next vector in the array, but either calculate our starting position with the 'extra' as a negative offset, or simply translate from our current position.
Answer by Eric5h5 · Mar 13, 2013 at 02:17 AM
Using MoveObject,
var points : Vector3[];
var time = 5.0;
function Start () {
for (var i = 0; i < points.Length-1; i++) {
yield MoveObject.use.Translation (transform, points[i], points[i+1], time, MoveType.Time);
}
}
Since MoveObject advances the third parameter of Lerp by using Time.deltaTime before setting the position, the object will never be stationary for one frame at the transitions, since it will never quite be at the starting point specified by the points in the array (though it will always end up exactly at the ending point).
Your answer
![](https://koobas.hobune.stream/wayback/20220613094311im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Lerp Movement Pauses after frame 2 Answers
Getting a 2d Sprite to move over time to an Array 1 Answer
Lerp Movement Forward Help 2 Answers
How to smooth my camera (Vector3.Lerp) 0 Answers
Movement Script 1 Answer