// Script for applying a small, random impulse to physical objects
// to make them float about.
//
// Note: There is no bound to where the objects go, this script
// is meant for objects in a physically bounded area (like a fish tank with a lid)
//
// Feel free to use as you wish, but do let me know if you find something
// interesting to do with it ...
//
// Kimm Paulino
// Written for Synonyme Toll, Sept 2009
//
// How often to apply the new impulse (in seconds)
float IMPULSE_TIME = 3.0;
// Range for the magnitude and x, y, z directions of the impulse
float IMPULSE_RANGE = 0.5;
float newRand (float range)
{
// Want a random number in range +- 'range'
return (llFrand(2.0*range) - range);
}
applySmallImpulse ()
{
vector my_vec = llGetVel();
float my_mag = llVecMag (my_vec);
vector my_dir = llVecNorm (my_vec);
// Change the magnitude slightly ...
my_mag = my_mag + newRand(IMPULSE_RANGE);
// Change the direction slightly too ...
my_dir = ;
vector new_vec = my_dir * my_mag;
//llOwnerSay ("Applying Impulse: " + (string)new_vec);
// apply the impulse to us
llApplyImpulse (new_vec, TRUE);
}
default
{
on_rez(integer n)
{
llResetScript ();
}
state_entry()
{
// Turn on Physics
llSetPrimitiveParams ([PRIM_PHYSICS, TRUE]);
// The following will stop it rotating and keep it facing the same direction if required
// llSetStatus(STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, FALSE);
// Set the boyancy to > 1.0 so that it floats
llSetBuoyancy (1.0);
// Set up a timer to apply an impulse
llSetTimerEvent (IMPULSE_TIME);
}
timer()
{
applySmallImpulse();
}
}