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