Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Bouncing Ball Mystery

Moose Pegler
Registered User
Join date: 22 Apr 2006
Posts: 33
11-18-2006 16:19
Below is my attempt at a bouncing ball. I'd appreciate any and all comments but what has me mystified is that I seem to need the two "llOwnerSay" statements in setVel to make it bounce at all. If I remove them the ball just sits there even when I 'touch' it or tell it to 'hop n'.

Any and all insight will be greatly appreciated.

Cheers, Moose

integer stop = TRUE;
integer bounces = 0;
float pulse = 10.0;
integer collisionUnderway = FALSE;

setVel(vector velocity)
{
llOwnerSay("Start setVel: "+(string)llGetVel());
llApplyImpulse(llGetMass() * (velocity - llGetVel()), FALSE);
llOwnerSay("End setVel: "+(string)llGetVel());
}

bounce()
{
if(stop)
{
// llOwnerSay("STOPPED: "+(string)llGetPos()+"/"+(string)llGetVel()+"/"+(string)llGetEnergy());
return;
}
else if(bounces > 5)
{
llOwnerSay("STOPPING";);
llApplyImpulse(-llGetMass()*llGetVel(), FALSE);
stop = TRUE;
return;
}
else
{
bounces++;
setVel(<0,0,1>;);
return;
}
}

default
{
on_rez(integer arg)
{
llResetScript();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
collisionUnderway = FALSE;
bounces = 0;
stop = TRUE;
}

state_entry()
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llListen(0, "", llGetOwner(), "";);
collisionUnderway = FALSE;
}

touch(integer num_detected)
{
bounces = 0;
stop = FALSE;
collisionUnderway = FALSE;
llSetPos(llGetPos()+<0, 0, 1.0>;);
}

listen(integer channel, string name, key id, string message)
{
list command = llParseString2List(llToLower(message), [" "], []);

if ((llGetListLength(command) > 1) && (llList2String(command, 0) == "hop";))
{
bounces = 0;
stop = FALSE;
collisionUnderway = FALSE;
llSetPos(llGetPos()+<0, 0, llList2Float(command, 1)>;);
bounce();
}
}

collision_start(integer num_detected)
{
if(!collisionUnderway)
{
collisionUnderway = TRUE;
bounce();
}
}

collision_end(integer num_detected)
{
collisionUnderway = FALSE;
}
}
Ina Centaur
IC
Join date: 31 Oct 2006
Posts: 202
11-18-2006 16:56
does Linden Labs not have a class supporting the proper highlighting of LSL scripts?!

From: Moose Pegler
Below is my attempt at a bouncing ball. I'd appreciate any and all comments but what has me mystified is that I seem to need the two "llOwnerSay" statements in setVel to make it bounce at all. If I remove them the ball just sits there even when I 'touch' it or tell it to 'hop n'.

Any and all insight will be greatly appreciated.

Cheers, Moose

CODE

integer stop = TRUE;
integer bounces = 0;
float pulse = 10.0;
integer collisionUnderway = FALSE;

setVel(vector velocity)
{
llOwnerSay("Start setVel: "+(string)llGetVel());
llApplyImpulse(llGetMass() * (velocity - llGetVel()), FALSE);
llOwnerSay("End setVel: "+(string)llGetVel());
}

bounce()
{
if(stop)
{
// llOwnerSay("STOPPED: "+(string)llGetPos()+"/"+(string)llGetVel()+"/"+(string)llGetEnergy());
return;
}
else if(bounces > 5)
{
llOwnerSay("STOPPING");
llApplyImpulse(-llGetMass()*llGetVel(), FALSE);
stop = TRUE;
return;
}
else
{
bounces++;
setVel(<0,0,1>);
return;
}
}

default
{
on_rez(integer arg)
{
llResetScript();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
collisionUnderway = FALSE;
bounces = 0;
stop = TRUE;
}

state_entry()
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llListen(0, "", llGetOwner(), "");
collisionUnderway = FALSE;
}

touch(integer num_detected)
{
bounces = 0;
stop = FALSE;
collisionUnderway = FALSE;
llSetPos(llGetPos()+<0, 0, 1.0>);
}

listen(integer channel, string name, key id, string message)
{
list command = llParseString2List(llToLower(message), [" "], []);

if ((llGetListLength(command) > 1) && (llList2String(command, 0) == "hop"))
{
bounces = 0;
stop = FALSE;
collisionUnderway = FALSE;
llSetPos(llGetPos()+<0, 0, llList2Float(command, 1)>);
bounce();
}
}

collision_start(integer num_detected)
{
if(!collisionUnderway)
{
collisionUnderway = TRUE;
bounce();
}
}

collision_end(integer num_detected)
{
collisionUnderway = FALSE;
}
}


Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
11-18-2006 17:04
we use [ php ] [ /php ]

CODE
integer stop = TRUE;
integer bounces = 0;
float pulse = 10.0;
integer collisionUnderway = FALSE;

setVel(vector velocity)
{
llOwnerSay("Start setVel: "+(string)llGetVel());
llApplyImpulse(llGetMass() * (velocity - llGetVel()), FALSE);
llOwnerSay("End setVel: "+(string)llGetVel());
}

bounce()
{
if(stop)
{
// llOwnerSay("STOPPED: "+(string)llGetPos()+"/"+(string)llGetVel()+"/"+(string)llGetEnergy());
return;
}
else if(bounces > 5)
{
llOwnerSay("STOPPING");
llApplyImpulse(-llGetMass()*llGetVel(), FALSE);
stop = TRUE;
return;
}
else
{
bounces++;
setVel(<0,0,1>);
return;
}
}

default
{
on_rez(integer arg)
{
llResetScript();
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
collisionUnderway = FALSE;
bounces = 0;
stop = TRUE;
}

state_entry()
{
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llListen(0, "", llGetOwner(), "");
collisionUnderway = FALSE;
}

touch(integer num_detected)
{
bounces = 0;
stop = FALSE;
collisionUnderway = FALSE;
llSetPos(llGetPos()+<0, 0, 1.0>);
}

listen(integer channel, string name, key id, string message)
{
list command = llParseString2List(llToLower(message), [" "], []);

if ((llGetListLength(command) > 1) && (llList2String(command, 0) == "hop"))
{
bounces = 0;
stop = FALSE;
collisionUnderway = FALSE;
llSetPos(llGetPos()+<0, 0, llList2Float(command, 1)>);
bounce();
}
}

collision_start(integer num_detected)
{
if(!collisionUnderway)
{
collisionUnderway = TRUE;
bounce();
}
}

collision_end(integer num_detected)
{
collisionUnderway = FALSE;
}
}
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura