Wednesday, July 2, 2008

Second Life Physics Scripting - Pinball #6 - Collision Tester


During this process I created a simple test of the ball bouncing through an object. It has a back wall script on the bottom wall which pushes the ball. I could move the middle wall closer and closer to test for the ball bouncing through at different speeds. I left it for a couple of days to test my theories and the speed change I made fixed the problems.

Here is the code for the back wall.


float maxspeed = 0.8;
default
{
collision_start(integer total_number)
{
//llOwnerSay("Collision start");
//llOwnerSay(llDetectedName(0) + " collided with me!");
if ((llDetectedName(0) == "ball") || (llDetectedName(0) == "ball2"))
{
// need to find the direction from the backwall to the ball
vector pos = llGetPos();
list a = llGetObjectDetails(llDetectedKey(0), ([OBJECT_POS]));
vector pos2 = llList2Vector(a,0);
pos.y = pos2.y; // so we don't get any side to side movement
vector pos3 = pos2-pos;
//llOwnerSay("pos = "+(string)pos);
//llOwnerSay("pos2="+(string)pos2);
pos3.x = pos3.x*1.5;
pos3.z = pos3.z*1.5;
float mag = llVecMag(pos3);
if (mag>maxspeed)
{
float magdev = maxspeed / mag;
pos3 = pos3 * magdev;

//mag = llVecMag(pos3);
//llOwnerSay("------adjusted mag down to "+(string)mag);
}
//llOwnerSay("pos3 = "+(string)pos3);
//llOwnerSay("mag3 = "+(string)llVecMag(pos3));
integer ra = (integer) llFrand(1.0)-1;
//pos3.y = pos3.y*ra;
//pos3.y = pos3.y*8;
//llPushObject(llDetectedKey(0), <8,0,1>, <0,0,0>, FALSE);
llPushObject(llDetectedKey(0), pos3, <0,0,0>, FALSE);
}
//llOwnerSay("Collision done");
}
}


The code in the ball was the same as the pinball I showed previously. It really just jiggled once in a while.

No comments: