Ball collision in pool game

Try it.

I tried it and each time my cue ball touches another ball it disappears and the ball my cue ball hits goes through everything.

(Canned Reply: ABG- Export & Upload .aia)
Export your .aia file and upload it here.

export_and_upload_aia

.

Final_Project.aia (100.7 KB)

Your code to set Headings in the procedure to handle Ball on Ball collision can't be right, because you are attempting to take the atan2 trig function of Ball1,Ball2 (two Ball component parameters.)

I would expect you would need two velocity values for those atan2() parameters.

Unfortunately, I don't know where you got your formulas for the bounce, so I have no immediate fix for you.

I suggest searching the Gallery for working samples, using the keywords "pool" or "billiards".

Here is some draggable code to catch collisions and deal with them appropriately:

score

This can replace all your ball edge reached events:

Final_Project (1).aia (101.2 KB)

You have a bunch of more work to do:

  • Find your collision math source and fix the collision procedure
  • Add procedures to
    • line up pockets at start of game by proportion of Canvas1.Height and .Width
    • line up balls at start of game by proportion of Canvas1.Height and .Width
  • call those procedures after the Canvas has finished displaying, a dozen milliseconds after Screen.Initialize

I think this code is from here:

1 Like