Many thanks to Lightwave Valkyrie for IMing this script to me in game:
vector velocity = <0,0,0>; // Initialization
float rebound = 1.50; // Rebound strength
collide()
{
vector comparison = llGetVel();
if(llVecMag(comparison) > 1)
{
if(llVecMag(llVecNorm(comparison) - llVecNorm(velocity)) > 1)
llApplyImpulse(llVecNorm(comparison) * llVecMag(velocity) * rebound * llGetMass(),FALSE);
else
llApplyImpulse(-1 * llVecNorm(comparison) * llVecMag(velocity) * rebound * llGetMass(),FALSE);
}
}
default
{
state_entry()
{
llCollisionSound("",0.0);
llSetTimerEvent(0.2);
llSetStatus (STATUS_ROTATE_X|STATUS_ROTATE_Y|STATUS_ROTATE_Z, FALSE);
}
collision_start(integer total_number)
{
collide();
}
land_collision_start(vector pos)
{
collide();
}
timer()
{
velocity = llGetVel();
}
}
The question is - why does it work?
I naively thought that simply calling
llApplyImpulse(-1 * comparison * rebound * llGetMass(),FALSE);
in the event handler would do the job.
Is the velocity of the object in collision_start the velocity before or after the collision?
Why is there the need to NOT * -1 in some cases?
I suspect the answers may be that sometimes the object passes slightly through the ground and therefore is heading in the opposite direction when the event fires.
Any insights on this wierdness would be much appreciated.
Thanks