PDA

Click to See Complete Forum and Search --> : help with pinball flippers..anyone?

firthy
05-29-2002, 06:55 AM
Hi, I hope someone on this list can give me some help towards making some flippers for a pinball game I’m making. This has proved far harder than I first expected. The flippers need to be able to “catch” the ball when in the up position and have the ball roll down them when in the down position---This all works fine. However problems start to arise with when the flippers are moving upwards. At the moment the ball tends to just pass through the ball when moving upwards. I need to work out

1. The flipper isMoving----done
2. what angle the flipper is and the line mc that makes up the top surface of the flipper are----done.
3. How far is the ball from the “pivot” of the flipper when hit, to enable the pivot distance , ball velocities, and flipper speed to workout the new ball velocities.—I’m finding this very hard! Here’s part of the code. If anyone would care to look at the code I’d be very, very grateful. The links below are the full code and demo.

http://www.pusherman.com/test/flipper_test7.html
http://www.pusherman.com/test/flipper_test7.swf

function flipperMove (flipper) {
if (flipper == flipperLeft) {
if (Key.isDown(Key.LEFT)) {
flipper.isMoving = true;

flipper._rotation = flipper._rotation-flipperSpeed;
if (flipper._rotation<=-45) {
flipper._rotation = -45;
flipper.isMoving = false;
}
} else {
flipper._rotation = 45;
flipper.isMoving = false;
}
} else if (flipper == flipperRight) {
if (Key.isDown(Key.RIGHT)) {
flipper.isMoving = true;
flipper._rotation = flipper._rotation+flipperSpeed;

if (flipper._rotation>=45) {
flipper._rotation = 45;
flipper.isMoving = false;
}
} else {
flipper._rotation = -45;
flipper.isMoving = false;
}
}
}

function flipperCheck (flipper) {
// is the ball within the x bounds of the flipper---------------
// check the lines that make up the flipper l0 being the top most--------
for(i=0;i<3;i++){

bounds=line.getBounds(_root);
if(ball._x<bounds.xMax && ball._x>bounds.xMin){

//rotate the co-ords of the current line and ball--------------
angle=(line._rotation+line._parent._rotation)*Math .PI/180;
point.x=line._x;
point.y=line._y;
flipper.localToGlobal(point);
x=ball._x-point.x;
y=ball._y-point.y;
cosa=Math.cos(angle);
sina=Math.sin(angle);
y1=cosa*y-sina*x;
vy1=cosa*vy-sina*vx;
//check the ball is hitting the line and moving
// in the right direction-----------
if(y1>=-ball._height/2 && y1<=vy1){
// is the flipper moving or is it stationary
// from the flipper function?
if(flipper.isMoving){
// here is the tricky part…
// get the rotation of the line and flipper
// which is the same as above..
// how far is the ball away from the flipper?
// use the distance and flipper speed and rotation
// to determine the ball’s resulting velocity!
// rotate co-ords for balls x,y

}else{
//flippers are not moving so….
// the ball is rotated to get it sit on the line and roll
y1=-ball._height/2;
x1=cosa*x+sina*y;
vx1=cosa*vx+sina*vy;
vy1*=bounce;
x=cosa*x1-sina*y1;
y=cosa*y1+sina*x1;
vx=cosa*vx1-sina*vy1;
vy=cosa*vy1+sina*vx1;
ball._x=point.x+x;
ball._y=point.y+y;
}

}
}
}
}
//Help!
[Edited by firthy on 05-29-2002 at 07:01 AM]