Advertisement
worstbull

'follower' for attached object ('follower' is the 1st child)

Sep 16th, 2014
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Object must be attached to center-attachment-point with zero vector/rotation offset.
  2.  
  3. integer iChildprim = 2; //linknumber of childprim
  4. float fTimer = 0.618; //timer-interval
  5. float fMinDistance = 0.2; //distance the avatar must walk/run.. before it is determined a position-change
  6. vector vLastPos; //stores last known position of the avatar
  7. vector vRelativeChildPos_BeforeAvatarmovement; //stores last known position of the childprim
  8. float fFallBehind = 0.25; //percentage of 'fall behind' of the childprim, while the avatar is moving
  9. integer iMOVING = FALSE;
  10. default
  11. {
  12.     state_entry()
  13.     {
  14.         //initial child pos
  15.         vLastPos = llGetPos(); //avatar position
  16.         llSetTimerEvent(fTimer);
  17.     }
  18.     on_rez(integer start_param)
  19.     {
  20.         llResetScript();
  21.     }
  22.     timer()
  23.     {
  24.         if (llGetAttached() == 0)
  25.         { //not attached, return.
  26.             return;
  27.         }
  28.         vector vPos = llGetPos(); //avatar position
  29.         vector vChildPos = llList2Vector(llGetLinkPrimitiveParams(iChildprim, [PRIM_POS_LOCAL]),0); //childprim-position
  30.         vector vAbsoluteChildPos = vPos+(vChildPos*llGetRot()); //get absolute position of the childprim in the sim
  31.         vector vAbsolutePos = vAbsoluteChildPos + ((vAbsoluteChildPos-vPos)*fFallBehind); //apply offset
  32.         vector vRelativeChildPos = (vAbsolutePos-vPos)/llGetRot(); //get relative position of the childprim in the sim
  33.         float fDistance = llVecDist(vPos, vLastPos);
  34.         if (fDistance >= fMinDistance && !iMOVING)
  35.         { //avatar moving (was not moving before)
  36.             iMOVING = TRUE;
  37.             llSetLinkPrimitiveParamsFast(iChildprim,[PRIM_POS_LOCAL,vRelativeChildPos]);
  38.             vRelativeChildPos_BeforeAvatarmovement = vChildPos; //preserve relative pos of childprim.
  39.         }
  40.         else
  41.         {
  42.             if (iMOVING)
  43.             {
  44.                 if (fDistance < fMinDistance)
  45.                 { //avatar stopped moving
  46.                     iMOVING = FALSE;
  47.                     //reset pos
  48.                     llSetLinkPrimitiveParamsFast(iChildprim,
  49.  
  50. [PRIM_POS_LOCAL,vRelativeChildPos_BeforeAvatarmovement]);                    
  51.                 } //else still moving, keep current relative position
  52.             } //else avatar not moving and not stopping, do nothing.
  53.         }
  54.         vLastPos = vPos;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement