01-03-2004 14:29
I just wanted to post a helpful utility function I use when manipulating object's moverment when close to a sim border.

The behavior with llMoveToTarget() and llSetPos() is that they move to the vector specified within the current sim, so... if the object moving happens to cross a sim border while moving, it completely throws the movement off.
CODE

vector getLocalVec(vector localCoords, vector regionCorner)
{
vector simOffset = regionCorner - llGetRegionCorner();
return simOffset + localCoords;
}

Basicly, what it does, is convert a local vector and a regionCorner into a vector that when put into moveToTarget() or setPos() *always* points to one global position, that doesn't change relative to what sim your in (just make sure you re-call this function when you cross a sim border).

Ive had many situations where this function would be useful, espicially where a physical object was moving and had the potential to cross a sim border.

Example usage:
CODE

vector startPos;
vector startSim;

vector getLocalVec(vector localCoords, vector regionCorner)
{
vector simOffset = regionCorner - llGetRegionCorner();
return simOffset + localCoords;
}

setPos(vector destination)
{
llSetStatus(STATUS_PHYSICS,FALSE);
float distance = llVecDist(destination,llGetPos());

while(distance > 0)
{
llSetPos(destination);
distance = llVecDist(destination,llGetPos());
}
}

default
{
state_entry()
{
startSim = llGetRegionCorner();
startPos = llGetPos();
llSetStatus(STATUS_PHYSICS,TRUE);
llApplyImpulse(<5,0,0>,FALSE);
llSetTimerEvent(1);
}
timer()
{
if(llVecDist(llGetPos(),startPos) > 30)
{
setPos(startPos,startSim);
}
}
}

==Chris
_____________________
October 3rd is the Day Against DRM (Digital Restrictions Management), learn more at http://www.defectivebydesign.org/what_is_drm