LlSitTarget: Difference between revisions
mNo edit summary |
No edit summary |
||
| Line 8: | Line 8: | ||
|func_desc=Set the sit location for the prim. The sit location is relative to the prim's position and rotation. | |func_desc=Set the sit location for the prim. The sit location is relative to the prim's position and rotation. | ||
|return_text | |return_text | ||
|spec | |spec=llSitTarget sets the position for the Agent Target (Advanced -> Character -> View Agent Target). The position of the target is based on '''rot''' and the '''offset'''{{Footnote|It is widely considered that the '''rot''' should not affect the position, this is an example of a {{Wikipedia|Lava_flow_(programming)|lava-flow}}. ~ {{JIRA|SVC-2277}}|It is widely considered that the '''rot''' should not affect the position, this is an example of a lava-flow. - SVC-2277|handle=rot-offset}}. | ||
|caveats=*Once a sit target is removed [[llAvatarOnSitTarget]] will only return {{LSL_Constant/NULL_KEY}}. | |caveats=*Once a sit target is removed [[llAvatarOnSitTarget]] will only return {{LSL_Constant/NULL_KEY}}. | ||
*There is no way to remove the Sit option from the pie menu. | *There is no way to remove the Sit option from the pie menu. | ||
**It will appear to be removed if the [[llSetSitText]] is set to a space " ". | **It will appear to be removed if the [[llSetSitText]] is set to a space " " or similar transparent string. | ||
*Attachments cannot be sat upon. | *Attachments cannot be sat upon. | ||
* | *'''rot''' affects the position of the sit-target in a non-intuitive way{{Footnote|handle=rot-offset}}. | ||
**llSetLinkPrimitiveParams | **[[llSetLinkPrimitiveParams]] is an easy work-around. | ||
** | **Animations are relative to the Agent Target, but the Agent Target isn't described by the animation. | ||
*[[llSitTarget]] does not update position of an already seated avatar. | *[[llSitTarget]] does not update position of an already seated avatar. | ||
**[[#UpdateSitTarget|UpdateSitTarget]] described below works around this problem. It works by converting the sit target information into a link position that | **[[#UpdateSitTarget|UpdateSitTarget]] described below works around this problem. It works by converting the sit target information into a link position that is passed along to [[llSetLinkPrimitiveParams]]. | ||
* '''offset''' is limited to 300.0 meters on each axis. The x, y and z components must be in the range [-300.0, 300] (-300.0 <= value <= 300). | * '''offset''' is limited to 300.0 meters on each axis. The x, y and z components must be in the range [-300.0, 300] (-300.0 <= value <= 300). | ||
** If they are outside the acceptable range they are rounded to the closest limit. | ** If they are outside the acceptable range they are rounded to the closest limit. | ||
Revision as of 00:49, 25 June 2009
| LSL Portal | Functions | Events | Types | Operators | Constants | Flow Control | Script Library | Categorized Library | Tutorials |
Summary
Function: llSitTarget( vector offset, rotation rot );| 0.0 | Forced Delay |
| 10.0 | Energy |
Set the sit location for the prim. The sit location is relative to the prim's position and rotation.
| • vector | offset | – | Additional position for the sit target in local prim coordinates. | |
| • rotation | rot | – | Additional rotation for the sit target relative to the prim rotation. |
If offset == <0.0, 0.0, 0.0> then the sit target is removed.
Specification
llSitTarget sets the position for the Agent Target (Advanced -> Character -> View Agent Target). The position of the target is based on rot and the offset[1].
Caveats
- Once a sit target is removed llAvatarOnSitTarget will only return NULL_KEY.
- There is no way to remove the Sit option from the pie menu.
- It will appear to be removed if the llSetSitText is set to a space " " or similar transparent string.
- Attachments cannot be sat upon.
- rot affects the position of the sit-target in a non-intuitive way[1].
- llSetLinkPrimitiveParams is an easy work-around.
- Animations are relative to the Agent Target, but the Agent Target isn't described by the animation.
- llSitTarget does not update position of an already seated avatar.
- UpdateSitTarget described below works around this problem. It works by converting the sit target information into a link position that is passed along to llSetLinkPrimitiveParams.
- offset is limited to 300.0 meters on each axis. The x, y and z components must be in the range [-300.0, 300] (-300.0 <= value <= 300).
- If they are outside the acceptable range they are rounded to the closest limit.
Examples
<lsl>default {
state_entry()
{
llSitTarget(<0.0, 0.0, 1.0>, ZERO_ROTATION); //The vector's components must not all be set to 0 for effect to take place.
}
}</lsl>
Useful Snippets
UpdateSitTarget
<lsl>//Sets / Updates the sit target moving the avatar on it if necessary. UpdateSitTarget(vector pos, rotation rot) {//Using this while the object is moving may give unpredictable results.
llSitTarget(pos, rot);//Set the sit target
key user = llAvatarOnSitTarget();
if(user)//true if there is a user seated on the sittarget, if so update their position
{
vector size = llGetAgentSize(user);
if(size)//This tests to make sure the user really exists.
{
//We need to make the position and rotation local to the current prim
rotation localrot = ZERO_ROTATION;
vector localpos = ZERO_VECTOR;
if(llGetLinkNumber() > 1)//only need the local rot if it's not the root.
{
localrot = llGetLocalRot();
localpos = llGetLocalPos();
}
pos.z += 0.4;
integer linkNum = llGetNumberOfPrims();
do{
if(user == llGetLinkKey( linkNum ))//just checking to make sure the index is valid.
{
llSetLinkPrimitiveParams(linkNum,
[PRIM_POSITION, ((pos - (llRot2Up(rot) * size.z * 0.02638)) * localrot) + localpos,
PRIM_ROTATION, rot * localrot / llGetRootRotation()]);
jump end;//cheaper but a tad slower then return
}
}while( --linkNum );
}
else
{//It is rare that the sit target will bork but it does happen, this can help to fix it.
llUnSit(user);
}
}
@end;
}//Written by Strife Onizuka, size adjustment provided by Escort DeFarge</lsl>
GetSitTarget
<lsl>list GetSitTarget(integer prim, key av) {//WARNING: llGetObjectDetails can introduce an error that goes as far as the 5th decimal place!
//This is highly unlikely to be ever noticed unless compounded over time.
//Do not use while moving (like in a moving vehicle)!!!
vector tp = llGetAgentSize(av);
if(tp)
{
if(prim == LINK_THIS)//llGetLinkKey doesn't like LINK_THIS
prim = llGetLinkNumber();
list details = [OBJECT_POS, OBJECT_ROT];
rotation f = llList2Rot(details = (llGetObjectDetails(llGetLinkKey(prim), details) + llGetObjectDetails(av, details)), 1);
rotation r = llList2Rot(details, 3) / f;
return [((llList2Vector(details, 2) - llList2Vector(details, 0)) / f) + (llRot2Up(r) * tp.z * 0.02638) - <0.0, 0.0, 0.4>, r]; } return [];
}//Written by Strife Onizuka</lsl>