This function moves my gameobject to a new random position, after it reaches the position, it stops, how can I get it to repeat so that once in random position 1, it moves to random position 2?
function Update() {
var rotation = Quaternion.LookRotation(target);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * smooth);
transform.position = Vector3.Lerp(transform.position, target, Time.deltaTime * smooth);
}
Something like this?
function RenewTarget()
{
var newTarget = target;
while( newTarget == target )
{
newTarget = targetList[ Random.Range( 0, targetList.Length - 1 ) ];
}
target = newTarget;
}
function Update() {
if( ( target - transform.position ).magnitude < arrivalRange )
{
RenewTarget();
}
var rotation = Quaternion.LookRotation(target);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * smooth);
transform.position = Vector3.Lerp(transform.position, target, Time.deltaTime * smooth);
}
hmm, unknown identifier: targetList
anyideas?
seon
February 24, 2009, 4:11am
4
You will need to create a list of targets in the targetList…
eg, put this at the top of your script.
var targetList : Vector3[];
and then in the editor, set how many target positions, and add them into the array of Vector3’s.
i tried that, it says index out of range?