-
Accurate Ball Phy
Hi all,
I have gone thru many threads here in flaashkit to und the behaviour of balls in a pool game.
I summarised all and treid to put them all in a swf.
Firstly I want to show it to all u people. But I dont have any webspace to put it online.
Anyway heres my prb:
for the sake of simplicity I have just a ball and one cue ball on the stage. The cue ball comes at a certain speed and hits the ball at some angle. The ball getting hit gets deflected and follows the path coorectly as defined by the angle of hit. But unfortunately the cue ball is following a path which is excatly oppsoite to the path of the ball.
This is correct if the cue ball hits staright to the ball (angle =0) but when it hits at an angle it shouldnt.
how do I sort it out?
thx
-
Heres the swf anyway,
http://flashzed.tripod.com/pool.swf
Hope it helps.
-
very good collision tut and samples here;
http://www.geocities.com/~dr_ericlin.../indexgeo.html
look for collision
-
thx for the link blinkOk.
I have alomost followed the same principles of ball collision as described in the links below
http://ericlin2.tripod.com/collision/collision5.html.
http://ericlin2.tripod.com/collision/bb5.html
http://ericlin2.tripod.com/collision/snooker5t.html
http://ericlin2.tripod.com/collision/snooker5.html
I am goofing up somewhere in my file.
But I want to learn from the mistakes that I have created here so that things can b clear for me.
I wanted someone to look up in to my file and see where the prb actually is.
I dont mind mailing the fla.
Pls help
Thx
-
heres the fla.
http://flashzed.tripod.com/pool.zip
hope it helps.
thx
right click and use the save as taget to save download the file.
direct link isnt working it seems
-
As a side note... search this forum for pool... the guy from electrotank (I forget his username now) posted some great links last time this subject was raised :)
-
Hi,
Heres the code:
Code on the cue ball(instance name "cue");
PHP Code:
onClipEvent (load) {
xbounce = 1;
ybounce = 1;
yspeed = 0;
frict = 2;
//xspeed = 2.5;
rad = _width/2;
rads = _width;
hitFrict = 1;
moveMent = "sstop";
}
onClipEvent (enterFrame) {
frict *= 0.98;
x = xspeed*frict
y = yspeed*frict
_x += x
_y += y
}
Code on the ball(instance name "ball");
PHP Code:
onClipEvent (load) {
innerBall.number=1;
hh = "";
xx = 1;
yy = 1;
defl = 1;
xbounce = 1;
ybounce = 1;
yspeed = 0;
frict = 1;
xspeed = 0;
rads = _width;
i = 0;
r = _width/2;
cueR = _root.cue._width/2;
tR = r+cueR;
ball1R = _root.ball1._width/2;
angV = 1;
hitHLine = "";
}
onClipEvent (enterFrame) {
trace(p);
//COllision wirh cue ball starts here
diffx = (_x-_root.cue._x);
diffy = (_y-_root.cue._y);
h = Math.sqrt((diffx*diffx)+(diffy*diffy));
ang = Math.atan2((diffy), (diffx));
angD = ang*(180/Math.PI);
if (hitt == "yes") {
_root.gotoAndStop(2);
_root.liner.nextFrame();
_root.liner1.nextFrame();
frict = 0;
_root.cue.frict = 0;
p += 1;
}
if (p>200) {
_root.gotoAndStop(3);
frict = 0.98;
_root.cue.frict = 0.98;
hitt = "";
}
if (tR>h) {
hitt = "yes";
i++;
if (i<2) {
_rotation = diffx/2;
angV = h;
_root.liner._x = _root.cue._x;
_root.liner._y = _root.cue._y;
_root.liner._rotation = angD;
_root.liner1._x = _root.cue._x;
_root.liner1._y = _root.cue._y;
_root.liner1._rotation = angD+90;
frict = 0.98;
_root.cue.hitFrict = 0.98;
x = Math.abs(_root.cue.x);
y = Math.abs(_root.cue.Y);
xspeed = diffx;
//*x;
yspeed = diffy;
//*y;
defl = diffy/10;
_root.cue.xspeed = -(diffx/20);//This is the spot where I need help, to define path of the cue after collision
_root.cue.yspeed = -(diffy/20);//This is the spot where I need help, to define path of the cue after collision
_root.cue.x = x;
_root.cue.y = y;
hh = "yes";
}
} else {
i = 0;
}
//Collision with ball10 ends here
if (frict<=0.008) {
i = 0;
frict = 0;
hh = "";
hitHLine = "";
}
frict *= 0.98;
_x += ((xspeed*frict)/10);
//*xx;
_y += ((yspeed*frict)/10);
//*yy;
//cue ball hitTest ends here.
}
Thx