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
- Can never move an object below the ground; attempting to do so will cause the object to be placed with its center at ground height.
- Limited to moving no more than 10m per call in any direction. If the distance is more than 10m, the object will move in the direction of the specified position, but will stop after 10m. This makes it very easy to use it for moving a long distance:
- Cannot position an object higher than 4096m.
- An object can be moved into an adjoining sim by specifying a position that is outside the sim but inside the above-mentioned 10m range. For example, if the object is in the sim Gibson at <117, 254, 22>, call and the object will move north into Bonifacio at <117, 3, 22> (259 - 256 = 3). To move south, use a negative value: For more information, see global coordinate.
- Delays 0.2 seconds between calls, making the maximum speed traversable with this function 50 m/sec.
- Drains energy. No error is returned if the object failed to move. Use llSetPrimitiveParams with PRIM_POSITION instead if this is a problem.
Examples
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).
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:
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:
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:
This article wasn't helpful for you? Maybe the
related article at the LSL Portal is able to bring enlightenment.
Functions |
Dynamics |
Link