Hi,
To jump straight into it. I have an object that has an array of stored positions to move to. It moves from 0-1 1-2 2-3 3-4 4-5 5-6, so up one at a time. My problem is it won’t touch position 6 and after moving to position 1, position 6 dissapears and then at pos 2, pos 0 dissapears. But on the object in editor the array remains intact. Animated Gif attached below of whats happening (hope it works it does in preview).
The code below is not my final code but just to figure out whats going on.
Transforms are by reference…since you had targetA and targetB set to the same objects as levels[0] and levels[6], those changed when targetA and B did. Anyway they aren’t even necessary:
var movementAllowed : boolean;
var speed : float;
var levels : Transform[];
function Start(){
Crawling();
}
function Crawling(){
for (i = 0; i < levels.Length-1; i++) {
yield MoveBetweenPoints(levels[i].position, levels[i+1].position, speed);
yield WaitForSeconds (2);
}
}
function MoveBetweenPoints (start : Vector3, end : Vector3, speed : float) {
var t = 0.0;
var rate = speed / Vector3.Distance(start, end);
while (t < 1.0) {
t += Time.deltaTime * rate;
transform.position = Vector3.Lerp(start, end, t);
yield;
}
}