float maxspeed = 0.42;
default
{
collision_start(integer total_number)
{
if (llDetectedName(0) == "ball")
{
// 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);
// direction from wall to ball
vector pos3 = pos2-pos;
pos3.x = pos3.x*4;
integer ra = (integer) llFrand(1.0)-1;
pos3.y = pos3.y*ra;
/// check the magnitude of the speed versus the max speed
float mag = llVecMag(pos3);
if (mag>maxspeed)
{
// limit the speed to the max magnitude
float magdev = maxspeed / mag;
pos3 = pos3 * magdev;
}
llPushObject(llDetectedKey(0), pos3, <0,0,0>, FALSE);
}
}
}
The Lindens chose this method to increase performance. The alternative would be to check for collisions multiple times during each fram as something moves. It would be nice if there were one more flag where you could turn on a finer granularity on an object, say multiple checks based on it's size, but for now it will have to be a slower game if I'm going to continue making a pinball game.
I created this contraption to test my scripts for bounce through. The pink ball just bounces up into the first wall and goes through it if it is going too fast. It hits the top wall without losing the ball and I can rerun the test. I have been able to get away with a little larger value than the object size because there is some immedite friction before it reaches the wall, but that just means that it WILL still happen so I'll need to account for a ball off the table, but it should/better be infrequent.
No comments:
Post a Comment