Hi! I have some flying bugs which move forward constantly, rotating towards their target. I’m struggling to find a way to give my bugs a slightly random heading like a butterfly might in nature. Does anyone know how this might be achieved?
Thanks!
var target:Vector3;
var timer:float;
var sec:int;
function Start () {
target = ResetTarget();
sec=ResetSec();
}
function Update () {
timer+=Time.deltaTime;
if(timer>sec){
target=ResetTarget();
sec=ResetSec();
}
transform.Translate(target*10*Time.deltaTime);
}
function ResetTarget():Vector3{
return Vector3(Random.Range(-2.0,2.0),Random.Range(-2.0,2.0),Random.Range(-2.0,2.0));
}
function ResetSec():int{
timer =0;
return Random.Range(1,3);
}
There you go, tested and working. The object changes direction randomly after a random amount of time.