A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: Accurate Ball Phy

  1. #1
    Junior Member
    Join Date
    Nov 2002
    Posts
    18

    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
    Where is this Flash Rocket Taking us ^|^

  2. #2
    Junior Member
    Join Date
    Nov 2002
    Posts
    18
    Heres the swf anyway,

    http://flashzed.tripod.com/pool.swf

    Hope it helps.
    Where is this Flash Rocket Taking us ^|^

  3. #3
    ism BlinkOk's Avatar
    Join Date
    Aug 2001
    Location
    , location, location
    Posts
    5,002
    very good collision tut and samples here;
    http://www.geocities.com/~dr_ericlin.../indexgeo.html
    look for collision
    Graphics Attract, Motion Engages, Gameplay Addicts
    XP Pro | P4 2.8Ghz | 2Gb | 80Gb,40Gb | 128Mb DDR ATI Radeon 9800 Pro

  4. #4
    Junior Member
    Join Date
    Nov 2002
    Posts
    18
    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
    Where is this Flash Rocket Taking us ^|^

  5. #5
    Junior Member
    Join Date
    Nov 2002
    Posts
    18
    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
    Last edited by flashGaul; 12-23-2002 at 09:17 AM.
    Where is this Flash Rocket Taking us ^|^

  6. #6
    Phantom Flasher... Markp.com's Avatar
    Join Date
    May 2000
    Posts
    16,034
    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

  7. #7
    Junior Member
    Join Date
    Nov 2002
    Posts
    18
    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;
        
    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;
        
    0;
        
    _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);
        
    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;
            
    += 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;
                
    Math.abs(_root.cue.x);
                
    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;
                
    _root.cue.y;
                
    hh "yes";
            }
        } else {
            
    0;
        }
        
    //Collision with ball10 ends here
        
    if (frict<=0.008) {
            
    0;
            
    frict 0;
            
    hh "";
            
    hitHLine "";
        }
        
    frict *= 0.98;
        
    _x += ((xspeed*frict)/10);
        
    //*xx;
        
    _y += ((yspeed*frict)/10);
        
    //*yy;
        //cue ball hitTest ends here.

    Thx
    Where is this Flash Rocket Taking us ^|^

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center