(none of the below is how to make it fancy, just the basics of working around the most common llSetPos limits and surprises.)
I am glad it is the root prim or a single prim you want to move this time, because it is easier to do (and to explain). Child prims (including avatars) will move along with the root, and you get to use sim coordinates directly.
The first way most people will try is to use plain old llSetPos. Like I mentioned before, that will only move you 10 meters and then get stuck, so that can cause trouble. In these examples we'll be moving 10 meters east and north, and 5 meters up, a total of 15.
// first example, move the prim the "simple" way.
// We will get stuck and not complete the move.
default {
touch_start(integer det) {
vector origPos = llGetPos();
vector howFar = <10.0, 10.0, 5.0>; // this would be a 15 meter move
llOwnerSay("we want to move " + (string) llVecMag(howFar) + " meters");
llSetPos(origPos + howFar); // try to do the move with plain llSetPos
// but plain old llSetPos can only do the 10 meters
llOwnerSay("we really moved " + (string) llVecDist(origPos, llGetPos()) + " meters");
// leave us in the new location for a few seconds, then put everything back.
llSleep(5.0);
llSetPos(origPos);
}
}
With a little llSetPos loop, we can work around the limitation.
// second example, move the prim with a loop to complete the distance.
// a simple llSetPos() loop to get us where we want to go.
BigSetPos(vector where) {
while(llVecDist(llGetPos(), where) > 10.0) {
llSetPos(where);
}
llSetPos(where);
}
default {
touch_start(integer det) {
vector origPos = llGetPos();
vector howFar = <10.0, 10.0, 5.0>; // this would be a 15 meter move
llOwnerSay("we want to move " + (string) llVecMag(howFar) + " meters");
BigSetPos(origPos + howFar); // try to do the move with plain llSetPos
// this number may not be exactly 15, floats are goofy like that.
llOwnerSay("we really moved " + (string) llVecDist(origPos, llGetPos()) + " meters");
// leave us in the new location for a few seconds, then put everything back.
llSleep(5.0);
BigSetPos(origPos);
}
}
Now, there is another problem. Do we always want to move north/east/up in relation to the world as above, or do we want to align movement with the prim? To make it happen in relation to the prim, we have to dip our toes, but only lightly, into rotation. Spin the prim off center in the editor, then try the above script, and see that the crookedness is ignored. The third version below will treat the top of the prim as "up" instead.
// third example, use llGetRot() on our destination so that movement is aligned
// with the prim instead of the world.
// a simple llSetPos() loop to get us where we want to go.
BigSetPos(vector where) {
while(llVecDist(llGetPos(), where) > 10.0) {
llSetPos(where);
}
llSetPos(where);
}
default {
touch_start(integer det) {
vector origPos = llGetPos();
// Factor in llGetRot() to allow for a "crooked" prim.
// This time we are only moving straight up by 15 meters, so it is easier
// to see what happens.
vector howFar = <0.0, 0.0, 15.0> * llGetRot(); // this would be a 15 meter move
llOwnerSay("we want to move " + (string) llVecMag(howFar) + " meters");
BigSetPos(origPos + howFar); // try to do the move with plain llSetPos
// but plain old llSetPos can only do the 10 meters
llOwnerSay("we really moved " + (string) llVecDist(origPos, llGetPos()) + " meters");
// leave us in the new location for a few seconds, then put everything back.
llSleep(5.0);
BigSetPos(origPos);
}
}