Jump to content

Simple Leash Script


Shymus Roffo
 Share

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

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

Recommended Posts

A simple leash script add the scripts to one prim then copy and wear it and you have a leash

integer lockon = FALSE;
float rope_length = 5.0; // Obviously, the length of the simulated rope. (It will stretch slightly longer than this, though)
float dampening = 0.04; // This dampens a fraction of the object's velocity every 0.1 seconds, if the rope is stretched.
float bouncing = 0.4; // How much the object "bounces" back after stretching the rope to the limit of its length.
float constant = 16.0; // The force constant of the rope. 
key target;
vector ropecolor;
list rope_effect = [];

default
{
    state_entry()
    {
        llListen(12345,"","","TEST123");
        llSetTimerEvent(5.0);
    }

    timer() 
    { 
        if ( !lockon )
        {  
            llWhisper(12345,"TEST123"); 
        } 
    } 
    
    listen(integer chan, string name, key id, string msg)
    {
        if (!lockon)
        {
            lockon = TRUE;
            llWhisper(12345,"TEST123");
            llSetTimerEvent(0.0);
            target = id;
            llSensorRepeat("", target, SCRIPTED, 20.0, PI, 0.1);
            rope_effect = 
            [
                PSYS_PART_FLAGS,            PSYS_PART_FOLLOW_SRC_MASK | PSYS_PART_FOLLOW_VELOCITY_MASK | PSYS_PART_TARGET_LINEAR_MASK | PSYS_PART_TARGET_POS_MASK,
                
                PSYS_SRC_PATTERN,           PSYS_SRC_PATTERN_DROP,
                PSYS_SRC_TARGET_KEY,        target,
                
                PSYS_PART_START_COLOR,      ropecolor,
                PSYS_PART_END_COLOR,        ropecolor,
                PSYS_PART_START_ALPHA,      1.0,
                PSYS_PART_END_ALPHA,        1.0,
                PSYS_PART_START_SCALE,      <0.05,1.0,1.0>,
                PSYS_PART_END_SCALE,        <0.05,1.0,1.0>,
                PSYS_SRC_TEXTURE,           "",
                
                PSYS_PART_MAX_AGE,          0.5,
                PSYS_SRC_BURST_RATE,        0.001,
                PSYS_SRC_BURST_PART_COUNT,  1
            ];
            
            llParticleSystem(rope_effect);
        }
    }
    
    sensor(integer num_detected)
    {
        vector i_pos = llGetPos();
        vector u_pos = llDetectedPos(0);
        
        if (llVecMag(u_pos-i_pos)>rope_length)
        {
            llSetForce(constant*llGetMass()*llVecNorm(u_pos-i_pos)*(llVecMag(u_pos-i_pos) - rope_length),FALSE); 
            llApplyImpulse( llGetMass() * llGetVel() * dampening * -1.0 , FALSE ); 
            vector wrongway = llVecNorm(i_pos - u_pos); 
            float wrongmag = ( llGetVel() - llDetectedVel(0) ) * wrongway; 
            if ( wrongmag > 0.0 ) 
            { 
                llApplyImpulse( llGetMass() * ( ( -1.0 - bouncing ) * ( wrongway * wrongmag ) ) , FALSE ); 
            } 
        }
        else 
        { 
            llSetForce( ZERO_VECTOR, FALSE ); 
        } 
    }
    
    no_sensor()
    {
        llSetForce( ZERO_VECTOR, FALSE );
    } 
}

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 4601 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...