Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Bounce?

Jabe Twang
Newbie
Join date: 3 Apr 2006
Posts: 12
04-23-2006 07:24
Hi All,

I'm a complete noob - so much so that I have had to cross post this as I don't know what forum it should go in!

I'm starting on what I thought would be a simple project - a space hopper! You know - those big rubber orange balls you sit on and bounce.

So I made a big orange rubber ball and gave it physics - but there doesn't seem to be a bounce parameter in the prim dialog. Is this something I can set in script?

Or am I going to have to script detecting collisions and applying an impulse?

Thanks for listening - I'm the one in the sandbox standing looking at an orange ball for hours on end :(
Argent Stonecutter
Emergency Mustelid
Join date: 20 Sep 2005
Posts: 20,263
04-23-2006 10:13
From: Jabe Twang
Or am I going to have to script detecting collisions and applying an impulse?
Yes.

And when you figure out how to get land collisions to work sanely, post here. :)
Exile Loudon
Aspiring Scripter
Join date: 10 Dec 2005
Posts: 122
04-23-2006 16:39
You can give it some buoyancy using "llSetBuoyancy" which will make it bounce, somewhat.
Jabe Twang
Newbie
Join date: 3 Apr 2006
Posts: 12
04-27-2006 01:21
Many thanks to Lightwave Valkyrie for IMing this script to me in game:

CODE

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