Jump to content

Move a sitting avatar with a child prim


Swimmie Chaffe
 Share

You are about to reply to a thread that has been inactive for 2090 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

I am wondering how I can move a child prim by script along with an avatar sitting on it. I noticed that with a usual poseball script,  if I change a position of a child prim with script after an avatar sits on it, the avatar stays in its original position. How can I script so that when a child prim's position changes, an avatar also moves with it?

If anyone can point me to an example script, I'd very much appreciate it!

Link to comment
Share on other sites

Hi Dora, thanks for your reply. So, do you think the only way to move an avatar along with a child prim would be move them separately -- a prim with llSetLocalPos and an avatar via llSitTarget? I would like to have an avatar-sat child prim float around (not Omega rotation) a root prim, and wonder if moving a prim and an avatar separately create a lag between movements of the two. If you have any advice, I'd love to hear!

Link to comment
Share on other sites

You don't move the avatar with llSitTarget; there's just a relevant code sample in the wiki entry for that function. You move both the avatar and the child prim with llSetLinkPrimitiveParamsFast(). In fact, both should move within the same frame using PRIM_LINK_TARGET, which is as close to simultaneous motion as makes no difference. (That's not to say this all is lag-free; quite the contrary.)

Link to comment
Share on other sites

Qie is right, that's about the only way to do it. If the script resides in the moving child prim, a link number for that prim to put in the function would be LINK_THIS. If a script resides in the root, you'll have to either find out the child prim link number manually and hardcode or have a special name for this child prim, then the link number can be found via the script. As for the sitting avatar, its link number would always be: llGetObjectPrimCount(key uuid) + 1

Link to comment
Share on other sites

What you need to do is already suggested by Qie and Ela.
I can only guess you have a struggle with the actual coding.
What is suggested is done in this line of code:

llSetLinkPrimitiveParamsFast( primLinkNumber, [PRIM_POS_LOCAL, primPosition, PRIM_ROT_LOCAL, primRotation, PRIM_LINK_TARGET, avatarLinkNumber, PRIM_POS_LOCAL, avatarPosition, PRIM_ROT_LOCAL, avatarRotation] );

It sets the child prim's position and rotation plus the avatars position and rotation in one function call.
I hope it is helpful.

You can get a lot more help from this forum if you post your coding attempts I am sure:)

Link to comment
Share on other sites

The last avatar seated will also be the value returned by llGetNumberOfPrims(), which counts the avatar(s) seated, unlike llGetObjectPrimCount(). In fact, one way to tell how many avatars are seated on the linkset is to subtract one from the other. And it's pretty easy to end up with more than one avatar sitting on a linkset, even if there's only one llSitTarget() or llLinkSitTarget() set anywhere in the linkset, so for anything serious, the script should handle that situation, too.

As a very silly example, the following should spin the first child prim (link number 2) and a seated avatar -- regardless of where the avatar is seated. It has a kind of sketch of how one might handle multiple sitting avatars on multiple child prims, but this would need a lot more work to be of any practical use. Also,I'd guess that in reality it would only move if the avatar is on the intended link's sit target, but I wanted to include the barest hint of the complexity of handling multiple avatars.

integer SITTERS_ALLOWED = 1;float SPIN_INCR = 0.1;   // radians to spin per intervalfloat MOVE_INTERVAL = 0.05;   // secondslist PRIM_LINKS_TO_MOVE = [2]; // for example, spin the first child prim (link # 2), along with avatarlist linksToMove;integer movingp;float spinSoFar;default{    changed(integer change)    {        if (CHANGED_LINK & change)        {            integer lastSitterLink = llGetNumberOfPrims();            integer primLinks = llGetObjectPrimCount(llGetKey());            integer numSittingAvatars = lastSitterLink - primLinks;            if (0 == numSittingAvatars)            {   // somebody stood                // perhaps stop an animation                llSetTimerEvent(0.0);   // stop moving stuff (including child prims)                movingp = FALSE;            }            else            if (SITTERS_ALLOWED < numSittingAvatars)            {   // unsit extra sitters (will always be just one, but...)                integer thisSitterLink = lastSitterLink;                integer allowedSitterLink = primLinks + SITTERS_ALLOWED;                do                    llUnSit(llGetLinkKey(thisSitterLink));                while (--thisSitterLink > allowedSitterLink);            }            else            {                linksToMove = PRIM_LINKS_TO_MOVE;                integer thisSitterLink = primLinks;                while (++thisSitterLink <= lastSitterLink)                    linksToMove += thisSitterLink;                if (!movingp)                {   // don't restart timer if already moving                    llSetTimerEvent(MOVE_INTERVAL); // start moving stuff                    movingp = TRUE;                }            }        }    }    timer()    {        rotation rot = llEuler2Rot(<0.0, 0.0, spinSoFar>);        list params = [PRIM_ROT_LOCAL, rot];        integer thisLinkIdx = llGetListLength(linksToMove);        while (--thisLinkIdx)            params += [PRIM_LINK_TARGET, llList2Integer(linksToMove, thisLinkIdx), PRIM_ROT_LOCAL, rot];        llSetLinkPrimitiveParamsFast(llList2Integer(linksToMove, 0), params);        spinSoFar += SPIN_INCR;    }}

 Hope this isn't more confusing than helpful.

Link to comment
Share on other sites

  • 5 years later...

HI everyone i have been experiencing problems with this too sorry to jump onto this thread but  I dont think from my experience that  llSetLinkPrimitiveParamsFast(Agent_link,[PRIM_POS_LOCAL,localpos]); is working as i have printed out my coordinates:

[01:08] (Localpos)Me:<9.19067, 242.69830, 21.12802>
[01:08] Root :<9.19067, 242.69830, 21.14366>
[01:08] Offset: -0.015638
[01:08] Hover: 0.116000
[01:08] Agent height: 0.998262
[01:08] Agent height - Hover: 0.882262

As you can see the position is quite correct as obtained from llCastRay(  data .When i run my code it places me in an entirely different location <-290,280,39> I am presuming then that  llSetLinkPrimitiveParamsFast(Agent_link,[PRIM_POS_LOCAL,localpos]); doesn't work as described here and that you must use llSitTarget(

I am a member of NCI Scripters and have aired this problem in thier group

 

Denise X

 

 

Link to comment
Share on other sites

I am providing  my code snipit in case it helps:

Handle_Avatar_position(key agent) {
     list params = llGetObjectDetails(agent, [OBJECT_HOVER_HEIGHT,OBJECT_POS,OBJECT_NAME]);
     float av_hover = llList2Float(params,0);
    

     vector me_v_GlobalPosition = llList2Vector(params,1);
     string Agent_name = llList2String(params,2);
     integer Agent_link = -65543;
     vector Agent_size = llGetAgentSize(agent);
     integer i =  llGetNumberOfPrims( );
     integer j;
          
    do {
         params = llGetObjectDetails(agent,([OBJECT_NAME]));  
         if(llList2String(params,0) == Agent_name) Agent_link = j;
        j+=1;
     } while (j< i+1 || Agent_link == -65543);
     
     params  = llGetLinkPrimitiveParams(LINK_THIS,[ PRIM_POSITION,PRIM_POS_LOCAL, PRIM_ROT_LOCAL ,PRIM_ROTATION,PRIM_SIZE ]);
     rt_v_GlobalPosition = llList2Vector(params,0);
     rt_v_LocalPosition = llList2Vector(params,1);
     rt_v_LocalRotation = llList2Rot(params,2);
     rt_r_GlobalRotation = llList2Rot(params,3);
     rt_sz_LocalSize = llList2Vector(params,5);
     
     list ray = llCastRay(me_v_GlobalPosition, me_v_GlobalPosition+<0,0,-.132>,[]);// RC_DETECT_PHANTOM,TRUE);
    llOwnerSay(llDumpList2String(ray,"|"));        
     list bb = llGetBoundingBox(agent);        
    llOwnerSay(llDumpList2String(bb,","));        
     vector top = llList2Vector(bb,1);        
     vector bottom = llList2Vector(bb,0);        
     vector center = (top+bottom)/2;        
        // vector mypos = llGetPos();        
     vector pos = llList2Vector(ray,1)+<0,0,(-bottom.z)>;        
         //llSetPos(pos);
         // Convert pos as local co-ords
     vector localpos = rt_v_GlobalPosition - pos;
     localpos.z += (-av_hover + (top.z-bottom.z));
     localpos.x = me_v_GlobalPosition.x;
     localpos.y = me_v_GlobalPosition.y;
     
      
      llOwnerSay("Me:"+(string)localpos);
      llOwnerSay("Root :"+(string)me_v_GlobalPosition);
      llOwnerSay("Offset: "+(string)(localpos.z-me_v_GlobalPosition.z));
      llOwnerSay("Hover: "+ (string)av_hover);
      llOwnerSay("Agent hieght: " + (string)(top.z-bottom.z));
      llOwnerSay("Agent hieght - Hover: " + (string)(-av_hover + (top.z-bottom.z)));
     // llSetLinkPrimitiveParamsFast(Agent_link,[PRIM_POS_LOCAL,localpos]);
     //   llSitTarget( vector offset, rotation rot );
      sittingPosition.z = (float)(-av_hover + (top.z-bottom.z));
      llSitTarget(sittingPosition,<0,0,0,1>);

Link to comment
Share on other sites

23 hours ago, VirtualKitten said:

     integer i =  llGetNumberOfPrims( );
     integer j;
          
    do {
         params = llGetObjectDetails(agent,([OBJECT_NAME]));  
         if(llList2String(params,0) == Agent_name) Agent_link = j;
        j+=1;
     } while (j< i+1 || Agent_link == -65543);

..what even is going on here?

23 hours ago, VirtualKitten said:

     vector localpos = rt_v_GlobalPosition - pos;
     localpos.z += (-av_hover + (top.z-bottom.z));
     localpos.x = me_v_GlobalPosition.x;
     localpos.y = me_v_GlobalPosition.y;

Here's your problem. You're setting local offset to your avatar's global position, which will inevitably put you in really odd places. 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2090 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...