Set the sit location for the prim. The sit location is relative to the prim's position and rotation.

Syntax

void llSitTarget( vector offset, rotation rot );

Forced delay: 0.0 seconds. Energy: 10.0.

Parameters

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

llSitTarget(ZERO_VECTOR, ZERO_ROTATION);

Examples

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.
    }
}
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.0, 0.4>;  //here is the workaround
        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
    }
}

Useful snippets

UpdateSitTarget

This function is primarily for use in objects that need to move seated avatars. It is most useful in poseballs, furniture and vehicles (just not while they are moving). There is also a UpdateLinkSitTarget() version of the function that can be found at: User:Strife_Onizuka/UpdateLinkSitTarget.

//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 sit target; 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();
            }
            integer linkNum = llGetNumberOfPrims();
            do
			{
                if (user == llGetLinkKey(linkNum))//just checking to make sure the index is valid.
                {
                    //<0.008906, -0.049831, 0.088967> are the coefficients for a parabolic curve that best fits real avatars. It is not a perfect fit.
                    float fAdjust = ((((0.008906 * size.z) + -0.049831) * size.z) + 0.088967) * size.z;
                    llSetLinkPrimitiveParamsFast(linkNum,
                        [PRIM_POS_LOCAL, (pos + <0.0, 0.0, 0.4> - (llRot2Up(rot) * fAdjust)) * localrot + localpos,
                         PRIM_ROT_LOCAL, rot * localrot]);
                    jump end;//cheaper but a tad slower than return
                }
            } while(--linkNum);
        }
        else
        {//It is rare that the sit target will bork, but if it does happen, this can help to fix it.
            llUnSit(user);
        }
    }
    @end;
}//Written by Strife Onizuka, size adjustment and improvements provided by Talarus Luan

GetSitTarget

This function is primarily for configuring sittargets for furniture. Sit an avatar on a box, position the box where you want them and use this function to read the sittarget so that it can be coded into the furniture. See /GetSitTarget for an example.

list GetSitTarget(integer prim, key av)
{//WARNING: This function is very good but not perfect. Do not repeatedly pass GetSitTarget to llSitTarget or UpdateSitTarget.
 //Do not use this on moving avatars or objects, the results will very likely be wrong.
    vector tp = llGetAgentSize(av);
    if (tp)
    {//llGetObjectDetails is used so the av is not required to be seated on the object with the sit target.
        list details = llGetLinkPrimitiveParams(prim, [PRIM_POSITION, PRIM_ROTATION]) + llGetObjectDetails(av, [OBJECT_POS, OBJECT_ROT]);
        rotation f = llList2Rot(details, 1);
        rotation r = llList2Rot(details, 3) / f;
        float fAdjust = ((((0.008906 * tp.z) + -0.049831) * tp.z) + 0.088967) * tp.z;
        return [((llList2Vector(details, 2) - llList2Vector(details, 0)) / f) + (llRot2Up(r) * fAdjust) - <0.0, 0.0, 0.4>, r];
    }
    return [];
}//Written by Strife Onizuka, size adjustment provided by Talarus Luan

See also

Events

Functions

Deep notes

Issues

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