dcsimg
A Flash Developer Resource Site

Page 2 of 3 FirstFirst 123 LastLast
Results 21 to 40 of 57

Thread: [Resolved] [Resolved] REQUEST: Billiard balls phisics...

  1. #21
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,507
    Bit-101, that's just sick.

    Good work.

  2. #22
    Senior Member tonypa's Avatar
    Join Date
    Jul 2001
    Location
    Estonia
    Posts
    8,227
    I just love this thread

    Magic

  3. #23
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    Bit, once again you amaze me man. One day.....one day I will be as good as you. Until then...I will just sit here and wonder.

  4. #24
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    it's just about learning the basics. i concentrate on one thing until i know it so cold i can code it in my sleep. then i just play with the different formulas. how many different ways can you combine elasticity, gravity, momentum, accelleration, rotation, bouncing, angles, etc. etc. ? it's endless.

  5. #25
    Senior Member
    Join Date
    Mar 2002
    Posts
    183
    yeah, it sure it about the basics. I have been learning physics and calculus and stuff like that for years, but I have only been scripting for like a month. I have all of these ideas that I know how to do with real-life formulas and stuff like that, I just don't know the exact script and code and things like that. As soon as I can get the basics, I will hopefully be able to start turning out some good stuff like you.

  6. #26
    Senior Member
    Join Date
    Sep 2000
    Posts
    128
    thats amazing! you can actually get the little ones to orbit the big ones for a short time.

  7. #27
    Information Architect Subway's Avatar
    Join Date
    Feb 2000
    Location
    Switzerland
    Posts
    4,779
    I've played around a bit with the file from BIT-101. It's now a good example to show how something in a perfect order can go in chaos really fast.

    http://www.zh-webdesign.ch/icomedia/chaos.swf

    Fredi

  8. #28
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    Originally posted by cadwallader
    thats amazing! you can actually get the little ones to orbit the big ones for a short time.
    yup. there's another one, i think on April 7th (www.bit-101.com) that does orbiting directly.

  9. #29
    School bully
    Join Date
    Dec 2001
    Posts
    303
    Originally posted by lesli_felix
    I was playing pool last night, and decided to watch the balls a little more closely....It does look very difficult.

    Simply doing accurate and fast hittesting is enough of a headache.

    Still, I'm going to have a go. Probably best to start off with a good hittest, and a basic bounce, then work out rebound angles and momentum afterward.

    Then there's spin, which REALLY messes things up.

    I imagine that a good pool game in flash would require some convincing pseudophsics, rather than using any of newton's equations etc.

    I've just put this together in flash, it looks neat, but it's useless at the moment, as the balls don't collide, I'll post again as soon as I've got some kind of hittest/rebound thing going on.

    http://www.proanimate.com/pool1.swf

    Use enter to accelerate the balls, if you want to play around with it, here's the source:

    http://www.proanimate.com/pool1.fla

    The system cannot find the file specified.

  10. #30
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,507
    My site's down, and will be for a little while.

    I'll upload a file later on my freehost.

    I'm getting a little further with the game, I'm playing around with different collision detection routines for the balls. Starting off with 16 balls in pool really slows the game down!!!

    Also trying to correctly simulate the friction of the table. Subtracting .1% each frame looks good, but the ball never actually hits zero velocity when you do that, so you have to increase the friction as velocity approaches zero, and arbitrarily stop the ball when the velocity goes below a certain point.

    I'm also playing around with things like balls casting dynamic shadows on the table, but this isn't any good on slower machines, unfortunately.

    There's quite a few hurdles to programming pool. Here's a few more I haven't even contemplated yet...

    Opponent AI
    Multiplayer capability
    Targetting, showing path of object ball if hit.
    Finding some decent sound FX

  11. #31
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    "friction" is quite often taken as a percentage of speed like that. i usually do it that way myself. but it's not physically accurate. it would actually be mathematically represented by an acceleration in the opposite direction of the motion, or a negative acceleration, if you will. so it would be a constant amount, but of course it would never actually reverse the direction of the object, only stop it.

    so say you have an object with velocity vx. (we'll limit it to the x-axis) if vx is positive, frictionx will be negative, and vice versa. if vx is less than frictionx, vx should simply be set to 0.

    Code:
    ball._x+=vx;
    if(vx>frictionx){
      vx-=frictionx;
    } else if(vx<-frictionx){
      vx+=frictionx;
    } else {
      vx=0;
    }
    as far as number of balls, yeah, my system seems to max out at 10 or so. after that, too clunky. i could work at optimizing, but the fact is theres a lot of math to do each frame.

  12. #32
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,507
    Bit-101

    To speed things up a bit, try using the basic hit-test before using the pythagoras distance test.
    Only use the pythagoras test if you get a positive result on the bounding-box hittest.

    Here's that bouncing demo you did to illustrate. I set the balls to 20. There's also a moock fps speedometer in there to give you a frame rate:

    http://www.btinternet.com/~proanimat...02modified.swf

    Now instead of this:
    checkColl(b(i), b(j));

    Use this:
    if (b(i).hitTest(b(j))){
    checkColl(b(i), b(j));
    }


    It goes from about 8fps to around 14fps on my machine:

    http://www.btinternet.com/~proanimat...2modified3.swf


    BTW, here's what I've got so far. It's non-interactive at the moment. I'm still looking for ways to speed it up on the break, which is the slowest part of the game.

    http://www.btinternet.com/~proanimate/pool6.swf


  13. #33
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    wow, that pool game looks nice.

    and it's kind of spooky seeing my files up there with stuff added to them!

    keep at it!

  14. #34
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    mamma mia...this is way cool and way too dif. for me I would sugest you guys look in the GamesForum for Xentor's Flash peer-to-peer VB thingie...

    http://board.flashkit.com/board/show...hreadid=303746

    thanx for the tut..

    ms

  15. #35
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,507
    Bit-101
    Being able to dissect your bouncing code helped a great deal, along with minger's explanation of the physics.
    Another thing I'm working on is a way of giving a ball a rotating spot, so you can see it rolling. I have a very vague idea of how this might be done, I'll post as soon as/if I work it out.


    Mad-Sci
    That looks very cool.

    I was wondering, whether you could apply your mass collision detection routine to pool balls??? I haven't looked at the code myself, so I don't know. But I'm sure the same principle could be used to speed things up.

  16. #36
    Senior Member Mad-Sci's Avatar
    Join Date
    Mar 2000
    Posts
    2,756
    I guess so..keep in mind that the way it works is one moving against many static,you may want to tweek it a bit

    ms

  17. #37
    I haven't looked through the code much in the files posted so far, but I haven't seen any that ensure the balls haven't passed through each other completely. Let's say you have two balls, each with a 3 pixel radius. They are moving on a collision path at 30 pixels per step and appear to go through eachother. Do any of the SWF's or FLA's address this issue? I have a feeling that would slow down flash quite a bit in a game like pool where there are many tests going on at once, but it is an essential element to consider if you are trying to write a billiards game.

  18. #38
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,507
    The only thing I've noticed is that the bounce angles and collision detection become a little less accurate as the balls get faster. This actually happens on a real table, as human accuracy decreases the faster the balls are hit.

    So it doesn't matter, as long as the increments each ball makes aren't big enough to pass through a ball at a direct angle.

    Another 'problem' I've noticed is that when you break the pack hard enough, two balls appear to overlap as they don't have enough space or anywhere to go. Anybody who's broken up hard enough on a real table will see the same thing, only the ball is forced upwards.

  19. #39
    Good point, but it is possible to keep the balls slow enough not to pass through in most cases, but what about two balls that are going should touch edges? That is tough to protect against. I know Yahoo's pool doesn't allow many pass throughs (even on edges).

    The problem wasn't addressed very well in the Samurai book, but I know it can be done. I know what you're saying about the slop factor at higher speeds, but game code can be precise since we don't have to worry about external forces. I don't think it will be all that difficult to fix.

  20. #40
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,507
    (I think) the yahoo pool is timebased, not framebased, so it's coded in a completely different way. If I remember correctly, the ball doesn't slow down in real time, but 'fast-forwards' to its final position.

    With frame-based pool, the innacuracy comes from having a ball move too far in one increment, so you need to make sure that the balls aren't ever moving more than a certain number of pixels per frame. If you want a ball moving quickly, and you're movie's running at 15fps, then this is easier said than done!

    Another thing to remember is that java is faster than flash, so you can afford more elaborate routines for hit-testing and physics. With actionscript, you have to try and get a good balance between realism and performance.

    I actually tried an experiment by putting a ball very slighly in the path of another in flash, and it only hit it when it was travelling below a certain speed. As I said before, this happily reflects the behaviour of a real table in that hitting a ball quickly at an almost 90 degree angle will often result in a miss.

    This gave me another idea (which I haven't tried) - What if you increased the size of the ball proportionally to it's speed to exactly compensate for this? As the ball gets faster, it's more likely to miss, so make it bigger! Not physically, but just the hit-radius.

    It's an approximate solution, but it could work...




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