Jump to content
Xiija

Link Sit Target woes

Recommended Posts

i hope when AVsitter is released i can just play with that, untill then -

 rez 2 boxes, link em and put this script in the child.

if i sit on the child and click that box, it moves my avatar, ... and is supposed to renew the sitTarget,

but when i stand and sit back down, the sit target is way off?

tried everything i can think of :(

thanx for any advice,

X

vector sitPos;
vector sitRot;
integer avLink;
string anim ;
list local;
vector mypos;
rotation myrot;
rotation R_avRot;
rotation V2Rrot;

updateSitTrg(integer link,vector avPos, vector avRot)
{     
       key user = llAvatarOnLinkSitTarget(LINK_THIS);
       vector size = llGetAgentSize(user);           
       R_avRot = llEuler2Rot(avRot * DEG_TO_RAD );   
       if(size)
       {                  
           local = llGetLinkPrimitiveParams(link, [PRIM_POS_LOCAL, PRIM_ROT_LOCAL]);                ;
           mypos = llList2Vector(local,0);
           myrot = llList2Rot(local,1);  
           mypos += avPos;
           myrot *= R_avRot;
           mypos.z -=  ( (size.z/2) - 0.375 ); // height adjust?
        
           llSetLinkPrimitiveParamsFast(link,
           [PRIM_POS_LOCAL,  mypos ,
            PRIM_ROT_LOCAL, myrot  ]);
            llOwnerSay("\n Sit Target after: \nPosition - " + (string)mypos + "\nRotation - " + (string)myrot);
            llLinkSitTarget(LINK_THIS,mypos * myrot , myrot); 
                  
         }
}
default
{
    state_entry()
    {   sitPos = <0.0, 0.0, 0.5>;
        sitRot = <0.0, 0.0, 0.0>;
        V2Rrot =  llEuler2Rot(sitRot * DEG_TO_RAD );   
        llLinkSitTarget(LINK_THIS,sitPos, V2Rrot); 
    }
    touch_start(integer total_number)
    {  llOwnerSay("\n Sit Target before: \nPosition - " + (string)mypos + "\nRotation - " + (string)myrot); 
       // sitPos += <0.05, 0.0, 0.0>;
       sitRot += <0.0, 0.0, 10.0>;
       updateSitTrg(avLink,sitPos,sitRot);     
    }
    changed(integer change)
    {
        if (llAvatarOnSitTarget() != NULL_KEY)        
         {  
             llRequestPermissions(llAvatarOnSitTarget(), PERMISSION_TRIGGER_ANIMATION);   
             llSetClickAction(CLICK_ACTION_TOUCH); 
             avLink = llGetNumberOfPrims();
         }
       else 
         {   llSetClickAction(CLICK_ACTION_SIT);       
             avLink = 0;
         }
    }    
    run_time_permissions(integer perm) 
    {
        anim = llGetInventoryName(INVENTORY_ANIMATION, 0);
        if (anim != "")
         {  llStopAnimation("sit");
            llStartAnimation(anim);
         }
    }   
}

 

Edited by Xiija

Share this post


Link to post
Share on other sites

I think the problem is 

 avLink = llGetNumberOfPrims();

Since you call llGetNumberOfPrims()  in the changed event, after the avatar has sat down, that returns the link number of the avatar, not the prim.  So when you try to set a sit target for avLink, you're trying to set a sit target for llGetObjectPrimCount(llGetKey()) + 1 -- that is, a link that's not a prim.

Since the script is in the child prim whose sit target you want to set, why are you bothering with link sit targets?   Why not simply use llSitTarget, which, if the script is in a child prim, sets a sit target for that prim anyway?

  • Like 1

Share this post


Link to post
Share on other sites

I don't see why you are messing with the sit target anyway.  All you have to do is move the av with SLPPF, leaving the sit target intact.  That is, use the routine as written but just remove its last line that says

llLinkSitTarget(LINK_THIS,mypos * myrot , myrot);

 

  • Like 1

Share this post


Link to post
Share on other sites

The only reason, to my mind, why you would need llLinkSitTarget is for the initial set-up, when you assign a sit target to as many links as you expect sitters on the object.    Then, as Rolig says, you use llSetLinkPPF to move the sitter into position as soon as she sits down.     You can then use llAvatarOnLinkSitTarget to reference the various avatars to animate them (you know that the first sitter is going to be llAvatarOnLinkSitTarget(LINK_ROOT), assuming you set up the sit targets that way, and that the second sitter is llAvatarOnLinkSitTarget(n).   You can then position and animate everyone from the root prim.  

But you don't need the sit targets to position people -- as Rolig says, llSetLinkPPFast does this as soon as the avatar sits on the linkset.

Share this post


Link to post
Share on other sites

I think the problem is that PRIM_POS_LOCAL is relative to the root, but a sit target is relative to the child it's assigned to. So setting mypos as the sit target won't work. The sit target offset would have to be local to the child prim.

 

  • Like 1

Share this post


Link to post
Share on other sites

the reason i'm doing this is , I have been trying to make a sit target setter HUD,... you drop the

script into any furniture cushion, wear the HUD, and use a keypad to move the avatar and set the sit target

for that cushion. I made a bunch of mesh bean bags and chairs, and was looking to be able to just drop

in a script, use a HUD and *presto* lol. i'll try subtracting or dividing the cushion pos & rot from the avatar

stuff and see if that helps... mebbe the AVsitter code will have some insights too .

**************

The sit target offset would have to be local to the child prim.

***************

   

mebbe something like....?

SetPositionLocalToCurrentPosition(vector local_position)
{
   llSetPos( llGetLocalPos() + (local_position * llGetLocalRot() ) );
}

 

or

  vector   pos2_obj = (pos_region - llGetRootPosition()) / llGetRootRotation();
  rotation rot2_obj = rot_region / llGetRootRotation();      

::shrugs::

**edit: a function from AV sitter ...

string convert_to_world_positions(integer num)
{
    list details = llGetObjectDetails(llGetLinkKey(llGetLinkNumber()), [OBJECT_POS, OBJECT_ROT]);
    rotation target_rot = llEuler2Rot(llList2Vector(ROT_LIST, num) * DEG_TO_RAD) * llList2Rot(details, 1);
    vector target_pos = llList2Vector(POS_LIST, num) * llList2Rot(details, 1) + llList2Vector(details, 0);
    return (string)target_pos + "|" + (string)target_rot;
}

 

Edited by Xiija
  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Xiija said:

the reason i'm doing this is , I have been trying to make a sit target setter HUD,... you drop the

script into any furniture cushion, wear the HUD, and use a keypad to move the avatar and set the sit target

for that cushion.

In that case, I don't understand why you're using llLinkSitTarget rather than llSitTarget.   

 

Share this post


Link to post
Share on other sites
1 hour ago, Xiija said:

I have been trying to make a sit target setter HUD,... you drop the

script into any furniture cushion, wear the HUD, and use a keypad to move the avatar and set the sit target

for that cushion.

That makes sense.  I am lazy enough that I should have done the same myself ages ago.  It would save me the time of setting sit targets manually.  I guess I haven't done it because I truly am lazy.  It only takes me a minute or two to set sit targets by hand, and I forget about writing a helper script until the next time.  I don't see anything wrong with your approach (except, as Innula commented, you don't need to use llSetLinkTarget to do it).  I think all you need to do is include an offset for the local pos and rot of the child prim in your calculation.

Edited by Rolig Loon

Share this post


Link to post
Share on other sites
3 hours ago, Xiija said:

the reason i'm doing this is...

I would try Strife's GetSitTarget function. Position the AV with llSLPPF, call the GetSitTarget function and set the sittarget with the return.

  • Like 3

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×