Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Object must be attached to center-attachment-point with zero vector/rotation offset.
- integer iChildprim = 2; //linknumber of childprim
- float fTimer = 0.618; //timer-interval
- float fMinDistance = 0.2; //distance the avatar must walk/run.. before it is determined a position-change
- vector vLastPos; //stores last known position of the avatar
- vector vRelativeChildPos_BeforeAvatarmovement; //stores last known position of the childprim
- float fFallBehind = 0.25; //percentage of 'fall behind' of the childprim, while the avatar is moving
- integer iMOVING = FALSE;
- default
- {
- state_entry()
- {
- //initial child pos
- vLastPos = llGetPos(); //avatar position
- llSetTimerEvent(fTimer);
- }
- on_rez(integer start_param)
- {
- llResetScript();
- }
- timer()
- {
- if (llGetAttached() == 0)
- { //not attached, return.
- return;
- }
- vector vPos = llGetPos(); //avatar position
- vector vChildPos = llList2Vector(llGetLinkPrimitiveParams(iChildprim, [PRIM_POS_LOCAL]),0); //childprim-position
- vector vAbsoluteChildPos = vPos+(vChildPos*llGetRot()); //get absolute position of the childprim in the sim
- vector vAbsolutePos = vAbsoluteChildPos + ((vAbsoluteChildPos-vPos)*fFallBehind); //apply offset
- vector vRelativeChildPos = (vAbsolutePos-vPos)/llGetRot(); //get relative position of the childprim in the sim
- float fDistance = llVecDist(vPos, vLastPos);
- if (fDistance >= fMinDistance && !iMOVING)
- { //avatar moving (was not moving before)
- iMOVING = TRUE;
- llSetLinkPrimitiveParamsFast(iChildprim,[PRIM_POS_LOCAL,vRelativeChildPos]);
- vRelativeChildPos_BeforeAvatarmovement = vChildPos; //preserve relative pos of childprim.
- }
- else
- {
- if (iMOVING)
- {
- if (fDistance < fMinDistance)
- { //avatar stopped moving
- iMOVING = FALSE;
- //reset pos
- llSetLinkPrimitiveParamsFast(iChildprim,
- [PRIM_POS_LOCAL,vRelativeChildPos_BeforeAvatarmovement]);
- } //else still moving, keep current relative position
- } //else avatar not moving and not stopping, do nothing.
- }
- vLastPos = vPos;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement