A Flash Developer Resource Site

Page 3 of 3 FirstFirst 123
Results 41 to 57 of 57

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

  1. #41
    Gross Pecululatarian Ed Mack's Avatar
    Join Date
    Dec 2001
    Location
    UK
    Posts
    2,954
    I was thinking of the ball going through another.

    And idea would be for the balls in turn to have an invisible hairline MC skewed to run from the balls curent position to somwhere 1 frame ahead of it using the current velocities. HitTest it with the other balls, though tihs carries the bounding box problem.

  2. #42
    Hmm.. well I am going to mess around with it and see if I can get it to work in spite of flash. I know going for english might be a bit much for flash, but I am sure it is possible to code it frame based and have the balls detect a hit even if according to step size they would have stepped through eachother.

  3. #43
    Senior Member
    Join Date
    Mar 2001
    Posts
    136

    Angry

    What happened to the people over here ??

    I am really impressed with mingers theory and bit 101's mastery in flash AS Vis-a-Vis trignometry.

    I have question to minger and bit 101.

    based on mingers theory I have built this samll swf. I have got evrything correct but the ball that is hitting the stationery ball isnt behaving properly it is not following mingers theory of the ball going in a direction that is -ve of the angle of the ball being hit.

    minger and bit 101 ur help pls !!!!!

    files :
    http://www.greyvector.com/hitAngle.swf
    http://www.greyvector.com/hitAngle.fla

    thnx

  4. #44
    Member
    Join Date
    Jan 2001
    Posts
    72
    I just need to know ONE thing...What are the equations and/or how do you determine how much of one balls momentum is transferred to the other ball. I have read all the posts and this is the one thing that doesn't come up. If the balls hit straight on, then all of the momentum is transferred, but if they dont hit straight on (which happens most of the time) then only a certain percentage of the momentum is transferred. PLEASE someone answer this.. THanks you sooo much!

  5. #45
    Member
    Join Date
    Jan 2001
    Posts
    72
    and in reply to var_flash_games's post here is the code for ball1 that will fix your problem:

    onClipEvent (enterFrame) {
    // trace(x);
    if (hit eq "yes") {
    x = xspeed*Math.cos(angle)*fric;
    y = yspeed*Math.sin(angle)*fric;
    _x += x;
    // _y += y;
    if (hitTest(_root.ball2)) {
    diffx = _root.ball2._x-_x;
    diffy = _root.ball2._y-_y;
    angle = (Math.atan2(diffy, diffx));
    angle2 = (180/Math.PI)*(Math.atan2(diffy, diffx));
    _root.ball2.hit = "yes";
    i += 1;
    if (i<=1) {
    _root.ball2.x = x;
    _root.ball2.y = y;
    }
    _root.line._x = _root.ball2._x;
    _root.line._y = _root.ball2._y;
    _root.line._rotation = angle2 +90;
    }
    if (fric<=0) {
    fric = 0;
    } else {
    fric -= 0.1;
    }
    }
    }
    onClipEvent (load) {
    hit = "yes";
    angle = 1;
    xspeed = 4;
    yspeed = 4;
    fric = 3;
    }


    There are still many problems, but the line works now.


  6. #46
    Senior Member
    Join Date
    Mar 2001
    Posts
    136

    Angry

    Hi DjBlaze thanx for your code.

    But I found no difference in the ball1 behaviour. Also the ball2 is now not following the hit angle it just keeps going staright no matter what the hitAngle is.

    Is it that I need to wqork around the code again ??

    Can u pls if possible edit the fla and post it again.

    I want the ball1 to follow a reverse direction of the hitAngle. And The ball2 to follow a direction defined by the hitAngle. How do I achieve it.

    Thanx....

  7. #47
    Senior Member
    Join Date
    Mar 2001
    Posts
    136

    Angry HELP ME !!!!

    Will some one PLS come out and help me !!!!!

    Or is it that I havent explained it well.

    I dont mind explaining it again and again and again ....

    EXPLAINATION :

    A moving cue ball hits a stationery ball. The statinery ball gets deflected and moves in the direction defdined by the angle of hit. well Its all working till here.

    But when the hit occurs the cue ball shoud ideally based on the laws of ball physics should deflect and move in the direction opp to that of the hit angle. How do I do this.

    refer to the above links for the files.

    thnx...........


  8. #48
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    the best explanation for all this, that ive found, has been in macromedia flash super samurai. jobe makar's chapter. it still took some working over to fully understand it though.

    basically, you need to know each ball's momentum (mass*velocity).
    then you need to know the angle of collision - the angle formed by the line between the two balls.
    then you need to determine how much of each ball's momentum lies on that angle, using some coordinate rotation type trig.
    then you apply your conservation of momentum forumas to the momentum on that angle.
    then you rotate the coordinates back to the stage coordinates, which will give you the ball's new momentums.

    simple!

    hehe.

    i've also seen some decent tutorials on this written for director. although the code was a bit different, the explanations were half decent. don't have the urls though. your best bet is to buy the book. well worth it for the other stuff in jobe's chapter alone, not to mention the other authors.

  9. #49
    Senior Member
    Join Date
    Sep 2001
    Posts
    443
    Now this thread is getting long, and it may be time to open a discussion about how much code you tell others about?

    I think lots of people have done movies using this type of physics, but I think they are all sitting back thinking:

    "well it took me x long to sort it out, why should I give away a nice neat function where you give in two balls'
    velocities and get their new velocities out." Me included!!!!!

    Anyone interested in having this conversation? or is it as I suspect an unwritten rule, based on a subjective scale of "blood and sweatiness"?

    And just to upset the ones who haven't "toiled hard or long enough" yet:

    http://194.131.128.207/flash/circlebounce/Movie1.swf

    swills

  10. #50
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    nice movie. for me the issue is more like: it would take me several hours to write out a concise, understandable explanation with all the formulas. i just might do that someday and put it up as a tutorial someday so that i can just hand out the link and end these long threads!

  11. #51
    Senior Member
    Join Date
    Mar 2001
    Posts
    136

    Angry

    Well, bit-101
    I am waiting for ur tutorials despartely !!!

    Ofcourse I have went thru most of ur tutorials on ur website.

    They are very useful.

    and swills its very impressive ur movie is, it also means that U have got the ball physics right !!!

    would u please share ur theory and how did u work around to get this thing done.

    Also I would be pleased if u can tell me where I need to work on in my fla so that I get the desired effect.

    thnx....

  12. #52
    Senior Member
    Join Date
    Mar 2001
    Posts
    136

    Angry

    hey swills I missed ur first line,

    well, why u feel its necessary to discuss on how much one should discolse his codes.

    opensource enables the development of the entire group and also it enhances the software tool value.

    This will only help people in developing some excting and extraordinary applications or games in flash which otherwise would have been not possible without sharing of knowldege !!!!!!!


  13. #53
    ....he's amazing!!! lesli_felix's Avatar
    Join Date
    Nov 2000
    Location
    London UK
    Posts
    1,506
    Actually, I disagree.

    On the one hand the open-source approach allows far more to be achieved by a community of developers, but this community has to be supported by developers who get down and work some things out for themselves.

    Of course, nobody can be expected to re-invent the wheel. I've never even contemplated writing my own javascript pop-up window routine, as there are so many good open-source ones out there.

    Some people claim they can't learn anything without seeing other people's code. This couldn't be further from the truth. I've learned much more from tackling problems by myself than I could ever have from seeing other people's work. For one thing, understanding code somebody else has written is 10 times harder than understanding your own.

    And let's not forget how rewarding it is to solve a problem yourself....

    Here's something I tried for ages to get to work in flash 5, eventually I gave up as it just wasn't possible. However, when MX came out, I tried it again with the new dynamic masking technique and it worked a treat.

    http://myweb.tiscali.co.uk/proanimate/rendertest.html

    mouse to change direction, cursors to move, enter/space to turn gravity on and off. shift/ctrl to turn extra friction on/off.

    When I have the time this'll turn into a kickass platform game.

  14. #54
    Senior Member
    Join Date
    Sep 2001
    Posts
    443
    lesli_felix

    I tend to agree. Its as though some aspects of coding become so much the norm that then open source is available for people to "catch up". Where-as maybe the good coders who don't show everything are, in effect, dragging everyone else up - in a good direction. No pain, no gain!

    By the way, love the ladybird, it seems MX could be useful after all! ha! ha!

    This was done in 5:
    http://194.131.128.207/flash/molecul...ulerotate.html

    I've tried to help some people on these boards and they've got really irrate because I haven't just given them an fla. You are right about trying to understand another persons code - A persons coding style is probably much worse than their hand-writing! Indecipherable!

    Anyone else have any comments?

    swills


    [Edited by swills on 07-16-2002 at 07:48 AM]

  15. #55
    Senior Member
    Join Date
    Mar 2001
    Posts
    136

    Post

    hey leslie,
    nice buggy work

    swills ur molecules where excellent impressive work !!!!

    thanx pals, atleast its good to c nice works and get inspired. Thats why I like this forum so much.

  16. #56
    Member
    Join Date
    Jan 2001
    Posts
    72
    nice, way to post your addresses on the net, expect a bomb in 1 or 2 weeks, smart move

    *note: this is not a threat I wont be sending anything, but you guys are retarded to fall for this and put your addresses online.*

  17. #57
    Junior Member
    Join Date
    Aug 2007
    Posts
    1
    Quote Originally Posted by lesli_felix
    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.

    Another way to speed things up would be to compare the *squared* values only in your collision detection test, and then work out the square root afterwards (only if a collision happens).

    //distance between two balls, squared
    var distance_SQUARED = dx*dx+dy*dy;

    //distance within which a collision would happen, squared.
    var collision_dist_SQUARED = (b1.radius+b2.radius)*(b1.radius+b2.radius);

    if (distance_SQUARED < collision_dist_SQUARED)
    {
    var dist = Math.sqrt(distSQ);
    var angle = Math.atan2(dy, dx);

    ... and so on

    Calculating square roots is very expensive. The above replaces it with a single multiplication. I've also moved the angel calculation so that it's only worked out after a collision.

    Anyhoo, nice job on the original code (and the math). It's very much appreciated.

    Cheers.

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