// Message loop friendly MoveToPos!
// We're using a timer to call llSetPrimitiveParams([PRIM_POSITION...so as to allow other // events to be responded to.
// THIS SCRIPT IS A TOTAL FREEBIE! Change it, sell it, call it your own, slather it in CheeseWhip,...I care not. Although if try to say wrote it everyone will know you lie

////////////////////////////////////////////////////////////////////////////////////////////////
vector g_vDestination = <0,0,0>;// Our destination...<0,0,0> is just the default
// Call MoveStart just ONCE to start movement
MoveStart(vector vDestination)
{
g_vDestination = vDestination;
llSetTimerEvent(0.3);//start the timer. It will call MoveToPos until g_vDestination is reached. 0.3 sec is a good value to use in llSetTimerEvent so as to allow other events to be triggered.
}
// No need to call MoveToPos() as it will be called by timer
MoveToPos()
{
vector vPos = llGetPos();
vector vMoveBig = g_vDestination - vPos;
float fDistance = llVecMag(vMoveBig);
if(fDistance > 10)// distance is greater than llSetPrimitiveParams can handle, so just 10m toward destination
{
vector vNewPos = vPos + llVecNorm(vMoveBig)*10;
llSetPrimitiveParams([PRIM_POSITION,vNewPos]);//moving
}
else //Yay! Almost there..just this one last move
{
llSetTimerEvent(0);// Stop the timer. You could also use llResetScript
llSetPrimitiveParams([PRIM_POSITION,g_vDestination]); //moving
g_vDestination = <0,0,0>; // reset to default
}
}
default
{
state_entry()
{
llSay(0, "Aztral Aeon says Hello!"
;}
// For test purposes i just used touch_start to cause movement.
touch_start(integer total_number)
{
vector vDest = <150,111,35>; //obviously you should change this to where YOU want to move
MoveStart(vDest);
}
// will call MovePos until destination reached and timer is ended. Must be used in your script
timer()
{
MoveToPos();
}
}
