Don't click here unless you want to be banned.

LSL Wiki : llSetPos

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org
llSetPos(vector pos)

Moves the prim to position pos. If the calling script resides in a single prim or the root of a linked object, then pos is in region coordinates, which are relative to the simulator's southwest corner. If the script resides in a child prim in a link set, the pos is relative to the root prim of the link set.

Notes


Examples

llSetPos(<128, 128, 25>);

This moves the object to the center of the simulator, at 25m height (unless it's more than 10m away from that point, or the ground is higher than 25m there).

while (llVecDist(llGetPos(), targetposition) > 0.001) llSetPos(targetposition);

Note: this does not work for a child prim because llGetPos always returns the location in region coordinates.

Note: There is a rare error here that can occur with multiple prim objects. It the object is moved to a position where part of it is below the ground level llGetPos() will never reach targetposition. The script will hang in an infinite loop recognizable by the fact that whenever you try to move the object it will snap back to its original position. A safer method inserts an escape if there is no change on llSetPos(). As here:

object_move_to(vector position) {
    vector last;
    do {
        last = llGetPos();
        llSetPos(position);  
    } while ((llVecDist(llGetPos(),position) > 0.001) && (llGetPos() != last));
}

Child Objects

For child prims in a linked set, the position is relative to the parent prim's position (object-local coordinates). This relative position can be retrieved using llGetLocalPos.

Example:
llSetPos(<0, 0, 1>);

This moves the child prim to a position 1m upwards along the Z-axis of the parent object.

Q: Shouldn't this be:
llSetPos(llGetPos() + <0, 0, 1>)?
A: No, not for child prims -- their position is always relative to the parent. If you want to move it relative to its current offset from the parent, you'd use:
llSetPos(llGetLocalPos() + <0, 0, 1>);.

Q: Can I use llSetPos on an attachment?
A: Yes, as of SL 1.7 this is possible. Note that relative positioning applies to them as well, including HUD attachments.

Q: It says that in the parent, llSetPos repositions the entire object, and in a child prim, the position is relative to the parent's. Does this mean that there's no way to reposition the parent relative to all the other children?
A: Correct. You could theoretically do something with linking and delinking the parent, but the easiest way to deal with this situation is to not get into it. Design your object in such a way that the parent need not be repositioned relative to its children.

Q: I need to set both the rotation and position of a prim at once. My object looks jerky and weird without it.
A: You want llSetPrimitiveParams.

Q: On a linked prim, how do I calculate the local coordinate from a script in the root?
A: It is anti-intuitive, but like this:
key keyObj = llGetLinkKey(i);
list a = llGetObjectDetails(keyObj,([OBJECT_POS])); <-- returns region coordinate
vector savedp = llList2Vector(a,0) - llGetRootPosition();
and later you can use this to set another prim to that location using:
llSetLinkPrimitiveParams(i,[PRIM_POSITION,savedp]); <-- expects local coordinate



This article wasn't helpful for you? Maybe the related article at the LSL Portal is able to bring enlightenment.

Functions | Dynamics | Link
There are 14 comments on this page. [Display comments/form]