Difference between revisions of "LlApplyImpulse"

From Second Life Wiki
Jump to navigation Jump to search
(it s not a force , but a momentum)
Line 10: Line 10:
|return_text|spec
|return_text|spec
|caveats=
|caveats=
*Sets an initial momentum on the object applied to the center of Mass . Momentum is the mass*velocity needed to get an initial movement of velocity if the object is not affected by other forces ( as the gravity )
*The [[llVecMag|magnitude]] of {{LSLP|momentum}} may be scaled back by the object's available energy.
*The [[llVecMag|magnitude]] of {{LSLP|momentum}} may be scaled back by the object's available energy.
|examples=
|examples=
Line 78: Line 79:
     }
     }
}
}
</lsl>
<lsl>
/*
Uselesse script , just to demo that
* the parameter is a momentum not a force
* the initial velocity * mass = momentum when there are no other forces ( collisions, gravity )
* the momentum is not capped to 20
integer tid;
vector initPos;
vector Impulse;
default
{
    state_entry()
    {
        llSetPhysicsMaterial(GRAVITY_MULTIPLIER,0,0,0,0);
        llSetStatus(STATUS_PHANTOM, TRUE);     
        llSetStatus(STATUS_PHYSICS, TRUE);
    }
   
    touch_end(integer n)
    {
        tid=llTarget(initPos=llGetPos(),30);
        llSetStatus(STATUS_PHYSICS, TRUE);
        Impulse = llGetMass()*<0,0,25>;
        llOwnerSay(llList2Json(JSON_ARRAY, [ "Setup a Momentum=", Impulse  ]));
        llApplyImpulse( Impulse , FALSE);
    }
    moving_start()
    {
        llOwnerSay(llList2Json(JSON_ARRAY, [ "Velocity= ", llGetVel(), "Force=",llGetMass()*llGetAccel(), "Momentum=", Impulse  ]));
    }
    not_at_target()
    {
        llSetTimerEvent(0.0);
        llTargetRemove(tid);
        llSetStatus(STATUS_PHYSICS, FALSE);
        llSetRegionPos(initPos);
     
    }
}
/* Example of results
["Setup a Momentum=","<0.000000, 0.000000, 183.181381>"]
[10:19] Object: ["Velocity=","<0.000000, 0.000000, 25.000002>","Force=","<0.000000, 0.000000, -0.171902>","Momentum=","<0.000000, 0.000000, 183.181381>"]
*/
</lsl>
</lsl>
|helpers
|helpers

Revision as of 09:23, 20 April 2014

Summary

Function: llApplyImpulse( vector momentum, integer local );
0.0 Forced Delay
10.0 Energy

Applies impulse to object

• vector momentum
• integer local

Instantaneous impulse. llSetForce has continuous push. "Instantaneous" seems to mean a one second impulse, as an application of a force (in newtons) equal to the object's mass (in kg) for one second will accelerate it to a velocity of 1 (in meters per second), which appears to be what happens with this function.

Caveats

  • Only works in physics-enabled objects.
  • Sets an initial momentum on the object applied to the center of Mass . Momentum is the mass*velocity needed to get an initial movement of velocity if the object is not affected by other forces ( as the gravity )
  • The magnitude of momentum may be scaled back by the object's available energy.

Examples

<lsl> // Rez an object, and drop this script in it. // This will launch it at the owner.

default {

   state_entry()
   {
       key ownerKey = llGetOwner();
       vector ownerPosition = llList2Vector(llGetObjectDetails(ownerKey, [OBJECT_POS]), 0);

// if the owner is not in the sim, stop fooling around

       if (llGetAgentSize(ownerKey) == ZERO_VECTOR)
           return;

// else

       llSetStatus(STATUS_PHYSICS, TRUE);
       vector objectPosition = llGetPos();
       vector direction = llVecNorm(ownerPosition - objectPosition);
       llApplyImpulse(direction * 100, 0);
   }

} </lsl> Make yourself a beer can, drop this script into it, and have some target practice. <lsl> vector gHome; integer gHit;

default {

   collision_start(integer num)
   {
       if (!gHit)
       {
           llSetTimerEvent(15.0);
           gHome = llGetPos();
           gHit = TRUE;
       }
       llSetStatus(STATUS_PHYSICS, TRUE);
       llTriggerSound("b90ed62a-2737-b911-bb53-6b9228bbc933",1.0);
       llApplyImpulse(llGetMass()*<0,0,5.0>,TRUE);
       llApplyRotationalImpulse(llGetMass()*<llFrand(1.0),llFrand(1.0),llFrand(1.0)>,TRUE);
       llResetTime();
   }
   
   land_collision(vector where)
   {
       if (llGetTime() < 0.5)
       {
           llResetTime();
           llApplyImpulse(llGetMass()*<0,0,llFrand(1.0)>,TRUE);
           llApplyRotationalImpulse(llGetMass()*<llFrand(1.0),llFrand(1.0),llFrand(1.0)>,TRUE);
       }
   }
   
   timer()
   {
       llSetStatus(STATUS_PHYSICS,FALSE);
       gHit = FALSE;
       llSetRegionPos(gHome);  // Send the can home, even if more than 10m away
       llSetRot(ZERO_ROTATION);
       llSetTimerEvent(0.0);
   }

} </lsl> <lsl> /* Uselesse script , just to demo that

  • the parameter is a momentum not a force
  • the initial velocity * mass = momentum when there are no other forces ( collisions, gravity )
  • the momentum is not capped to 20
integer tid;
vector initPos;
vector Impulse;

default {

   state_entry()
   {
       llSetPhysicsMaterial(GRAVITY_MULTIPLIER,0,0,0,0);
       llSetStatus(STATUS_PHANTOM, TRUE);      
       llSetStatus(STATUS_PHYSICS, TRUE);


   }
   
   touch_end(integer n)
   {
       tid=llTarget(initPos=llGetPos(),30);
       llSetStatus(STATUS_PHYSICS, TRUE);
       Impulse = llGetMass()*<0,0,25>;
        llOwnerSay(llList2Json(JSON_ARRAY, [ "Setup a Momentum=", Impulse  ]));
       llApplyImpulse( Impulse , FALSE);
   }
   moving_start()
   {
       llOwnerSay(llList2Json(JSON_ARRAY, [ "Velocity= ", llGetVel(), "Force=",llGetMass()*llGetAccel(), "Momentum=", Impulse  ]));
   } 
   not_at_target()
   {
       llSetTimerEvent(0.0);
       llTargetRemove(tid);
       llSetStatus(STATUS_PHYSICS, FALSE);
       llSetRegionPos(initPos);
      
   } 

}

/* Example of results ["Setup a Momentum=","<0.000000, 0.000000, 183.181381>"] [10:19] Object: ["Velocity=","<0.000000, 0.000000, 25.000002>","Force=","<0.000000, 0.000000, -0.171902>","Momentum=","<0.000000, 0.000000, 183.181381>"]

  • /
</lsl>

See Also

Functions

•  llApplyRotationalImpulse
•  llSetForce Set continuous force

Deep Notes

Unpredictability

Taken from Simulator User Group/Transcripts/2012.10.05

[16:24] Andrew Linden: the llApplyImpulse() is even more unpredictable
[16:24] Andrew Linden: because it uses the legacy script "energy budget"
[16:25] Andrew Linden: which will attenuate the results if the scripted object doesn't have enough "energy" to execute the impulse that it wants
[16:25] Andrew Linden: also, that llApplyImpulse() has great griefing potential
[16:25] Andrew Linden: so we hobbled it a long time ago with a very high energy consumption rate

Signature

function void llApplyImpulse( vector momentum, integer local );

Haiku

In this crazy world,
Force, momentum, energy
cease to be conserved