Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

bounce or push an object

Gene Jacobs
Who? Me?
Join date: 30 Jul 2004
Posts: 127
08-25-2004 10:46
Does anybody have a script for when an object (lets say a ball) with physics set, touches another object, there will be a bounce or push away?
Kind of like a way, to put a ball in a tube. When the ball touches the bottom, it is repelled or bounces. The action will allow the ball to fall back down and continue the cycle.
_____________________
SL Defined = The reason that we are all here, is because we are not all there... :p
Wednesday Grimm
Ex Libris
Join date: 9 Jan 2003
Posts: 934
08-25-2004 11:19
Well, you have llGetPos(), which returns the object's position, and you have llDetectedPos(), which you can call in a collision_start() event to get the position of the object you're hitting.

As long as the object you're colliding with is relatively small, and not a weird cut shape, llGetPos() - llDetectedPos(0) will give you a vector away from the object you collided with.

So you could have something like
CODE
force fForce = 9.8; // how hard to push the object 
bounce(vector vDir)
{
vector vImp;
vImp = llVecNorm(vDir);
vImp = vForce * vImp;
llApplyImpulse(vImpFalse);
}

then in your state:
CODE
collision_start(integer n)
{
bounce(llGetPos() - llDetectedPos(0));
}
_____________________
Sarcasm meter:
0 |-----------------------*-| 10
Rating: Awww Jeeze!