Difference between revisions of "LlSitTarget"

From Second Life Wiki
Jump to: navigation, search
(Undo revision 1179693 by Talarus Luan (Talk))
(Reverted the edit.. needs a bit more testing before rolling out.)
Line 65: Line 65:
 
UpdateSitTarget(vector pos, rotation rot)
 
UpdateSitTarget(vector pos, rotation rot)
 
{//Using this while the object is moving may give unpredictable results.
 
{//Using this while the object is moving may give unpredictable results.
 
 
     llSitTarget(pos, rot);//Set the sit target
 
     llSitTarget(pos, rot);//Set the sit target
 
     key user = llAvatarOnSitTarget();
 
     key user = llAvatarOnSitTarget();
Line 81: Line 80:
 
                 localpos = llGetLocalPos();
 
                 localpos = llGetLocalPos();
 
             }
 
             }
 +
            pos.z += 0.4;
 
             integer linkNum = llGetNumberOfPrims();
 
             integer linkNum = llGetNumberOfPrims();
 
             do{
 
             do{
 
                 if(user == llGetLinkKey( linkNum ))//just checking to make sure the index is valid.
 
                 if(user == llGetLinkKey( linkNum ))//just checking to make sure the index is valid.
 
                 {
 
                 {
                     llSetLinkPrimitiveParamsFast( linkNum,
+
                     llSetLinkPrimitiveParams(linkNum,
                        [PRIM_POS_LOCAL, pos + <0.0, 0.0, 0.4> - ( llRot2Up( rot ) * 0.05 ),
+
                                            [PRIM_POSITION, ((pos - (llRot2Up(rot) * size.z * 0.02638)) * localrot) + localpos,
                        PRIM_ROT_LOCAL, rot] );
+
                                            PRIM_ROTATION, rot * localrot / llGetRootRotation()]);
 
                     jump end;//cheaper but a tad slower then return
 
                     jump end;//cheaper but a tad slower then return
 
                 }
 
                 }
Line 98: Line 98:
 
     }
 
     }
 
     @end;
 
     @end;
}//Written by Strife Onizuka, size adjustment provided by Escort DeFarge
+
}//Written by Strife Onizuka, size adjustment provided by Escort DeFarge</lsl>
// Updated version for more accuracy, using new PRIM_LOCAL_* rules, and llSetLinkPrimitiveParamsFast by Haravikk Mistral/tl</lsl>
+
 
===GetSitTarget===
 
===GetSitTarget===
 
<lsl>list GetSitTarget(integer prim, key av)
 
<lsl>list GetSitTarget(integer prim, key av)

Revision as of 12:34, 5 July 2013

Summary

Function: llSitTarget( vector offset, rotation rot );

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.
  • Removing or deactivating the script that sets the sit target will not remove the prim's sit target.
    • Sit target is a prim property and not dependent on a script for its continued existence.
  • To remove sit target, use the following:

<lsl>llSitTarget(ZERO_VECTOR,ZERO_ROTATION);</lsl>

  • Shift-copying a prim with a sit target, without a script that will set the sit target again, will not keep the sit target on the copy. (The copy is in the original location when shift-copying.)
  • There is no way to remove the Sit option from the menu.
    • It will appear to be removed if the llSetSitText is set to a space " " or similar transparent string.
  • Attachments cannot be sat upon (see SVC-6100 to vote for such a feature).
  • rot affects the position of the sit-target in a buggy way way.
    • To correct for the rot bug, simply subtract <0,0,0.4> from the position when rot is zero. See example below.
    • llSetLinkPrimitiveParams is a more difficult 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.
  • offset is limited to 300.0 meters on each axis. The x, y and z components must be in the range [-300, 300.0][2].
    • If they are outside the acceptable range they are rounded to the closest limit.
  • If an object has multiple seats (each seat has a script that sets a sit target, or the linkset has a script that assigns several llLinkSitTargets), the following method determines which sit target an avatar ends up at:
    • If the prim that is clicked on has a sit target and that sit target is not full, that sit target is used.
    • If the prim that is clicked on has no sit target, and one or more other linked prims have sit targets that are not full, the sit target of the prim with the lowest link number will be used.
All Issues ~ Search JIRA for related Bugs

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> <lsl>default //example with work-around for llSetTarget rot bug { //place in any prim large enough to sit on at any angle

           //click once to choose a place to sit, a second time to sit there
   touch_start(integer num)
   {
       vector pos=llDetectedTouchPos(0);       //use touch to set sit target
       vector lft=llDetectedTouchBinormal(0);  //use normals to rotate avatar to
       vector up=llDetectedTouchNormal(0);     //sit upright
       rotation rot=llAxes2Rot(lft%up,lft,up)/llGetRot();  //rotate avatar to stand there
       vector siz=llGetAgentSize(llDetectedKey(0));
       pos += 0.65*siz.z*up;       //this places MY avatars feet close to the surface
       pos = (pos-llGetPos())/llGetRot();  //llSetTarget expects local co-ordinates
       if (rot!=ZERO_ROTATION) pos -=<0,0,0.4>;  //here is the work around
       llSitTarget(pos,rot);
       llSetClickAction(CLICK_ACTION_SIT);   //switch to sit for second click
   }
   changed(integer change)
   {
       if (llAvatarOnSitTarget()==NULL_KEY)    //if they unsit,
           llSetClickAction(CLICK_ACTION_TOUCH);   //go back to click mode
   }
}</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>

See Also

Events

•  changed

Functions

•  llLinkSitTarget
•  llSetSitText
•  llAvatarOnSitTarget
•  llAvatarOnLinkSitTarget
•  llUnSit

Deep Notes

All Issues

~ Search JIRA for related Issues
   llSit() - scriptable ability to force an avatar to sit on an object
   Ability to sit on prims attached to avatars

Footnotes

  1. ^ It is widely considered that the rot should not affect the position, unfortunately the sit target code is a lava-flow. ~ SVC-2277
  2. ^ The ranges in this article are written in Interval Notation.

Signature

function void llSitTarget( vector offset, rotation rot );