After read a lot about ball physics, watch some examples and few days of trying making pinball with bitmaps, I need help. I use simple (easy to work with) and fast performance Physics AS3 engine for bitmaps http://coreyoneil.com/portfolio/index.php?project=5 but still cant fix following problem: if ball is moving too fast and object on path is too small, there will be no collision detection (code works perfect only with bigger objects or if ball is moving slower). I am not good at physics and maths. Here is function code which make physics for ball on every frame rate (but maybe its better to change it to setTimeout):
function showFrame(e:Event) // onEnterFrame
{
var collisions:Array = collisionlist.checkCollisions();
if(collisions.length) // if collision
{
var collision:Object = collisions[0]; // get collision information
var angle:Number = collision.angle; // get collision angle
var overlap:int = collision.overlapping.length; // get collision overlap
var sin:Number = Math.sin(angle);
var cos:Number = Math.cos(angle);
var vx0:Number = vx * cos + vy * sin;
var vy0:Number = vy * cos - vx * sin;
vx0 = ((mass - immovable) * vx0) / (mass + immovable); // var immovable:Number=10000; var mass:Number=immovable*2;
vx = vx0 * cos - vy0 * sin;
vy = vy0 * cos + vx0 * sin;
vx -= cos * overlap / radius; // radius=Math.round(ball.width/2);
vy -= sin * overlap / radius;
vx += speed; // var speed:Number=0;
}
vy += gravity; // var gravity:Number=0.75;
vy *= friction; // var friction:Number=0.981;
vx *= friction;
ball.x += vx;
ball.y += vy;
//setTimeout(showFrame, 20);
}
You could use sub steps.
Its simple but works nicely, basically you divide your velocities by how many steps you want, then have a for loop that tests for collisions on those increments.
Here is a good example/tutorial: http://www.samclifton.com/tutorials.php?tut=2