Jump to content
Iva Rhapsody

stopping an object short of it's target

Recommended Posts

I tend to get turned around any time rotations come into play :)

I'm using the following code to point an objects x axis towards a target position and moving it to it via llMoveToTarget and it works just fine however I want it to actually stop .5 meters short of the actual target, can anybody point me in the right direction laughs...

Next()
{
        index++;
        if (index >= llGetListLength(targets))
        {
            index=0;
        }
        target = llList2Vector(targets,index);
        mytarget =  llTarget( target, .3 );
        float dist=llVecDist(target,llGetPos());
        integer speed2=6 - llList2Integer(speeds,index);
        llMoveToTarget( target, speed2*(dist/4));
        vector pos =  llGetPos();
        llRotLookAt( llRotBetween( <1.0,0.0,0.0>, llVecNorm( <target.x,target.y,pos.z> - pos ) ), 1.0, .2);
    }  
}

Edited by Iva Rhapsody

Share this post


Link to post
Share on other sites

mytarget = llTarget(target,0.5);

You can test that this will stop you 0.5m from the target by watching to see when the at_target and not_at_target events are triggered (example scriptlets from the LSL wiki):

at_target(integer tnum, vector targetpos, vector ourpos)
    {
        if (tnum == mytarget)
        {
            llOwnerSay("object is within range of target");
            llOwnerSay("target position: " + (string)targetpos + ", object is now at: " + (string)ourpos);
            llOwnerSay("this is " + (string)llVecDist(targetpos, ourpos) + " meters from the target");
            llTargetRemove(mytarget);
        }
    }
    not_at_target()
    {
        llOwnerSay(
            "not there yet - object is at " + (string)llGetPos() +
            ", which is " + (string)llVecDist(target_pos, llGetPos()) +
            " meters from the target (" + (string)target_pos + ")"
        );
    }
  • Like 1

Share this post


Link to post
Share on other sites

It seems that the object continues to "coast" along afterwards, when I remove the target I trigger an animation(hiding, showing certain surfaces on the objects mesh and releasing particles..this appears to occur at 2.75 meters which is the distance I decided on so that the object just touches the target object ie. offsetting centers so the edges meet, but the object in motion continues on and punches into the target...any ideas ?

Edited by Iva Rhapsody

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...