Setting up collision in certain sequence question

I have a pool program that I am trying to complete, I have 4 balls, a cue, an 8 ball and a blue and green ball. The problem i am facing is the cuball cannot directly hit the 8 ball and have it go into a pocket. If it does the game is over. However, if the 8 ball is the only ball besides the cue ball left on the table I can sink that ball for the win. Any one have an idea how i can accomplish this?

Please download and post each of those event block(s)/procedures here ...
(sample video)

Also

Export your .aia file and upload it here.
export_and_upload_aia

You can simplify your code using generic (Any Ball) event blocks and lists of Balls and of Sprites.

That reduces collision tests to IS IN LIST tests.

Here is an old Billiards sample of mine, unfortunately from before such conveniences were introduced, just for the bounce angle calculations ...

P.S. Proper analysis of your app would require its source (.aia) file.

eightBStudentCopy_2 (1).aia (10.1 KB)

tell us your questions rather than give a aia file.

use any sprite. collided to detect the collision may be not a good idea.

for example, when two balls collided, i want them to switch direction and speed like in the pool game. but when i use any ball .collided, this will be called twice, the result is the direction and speed do not change.

1 Like

I am also working on this problem. So far, we've barely started learning procedures/functions and how to implement them on a very minimal scale. Currently, the conundrum we're facing is we can use the given method "collided with" to see if it has made contact. However, we're both stuck with how to make the system identify if the cue ball collides with the eight ball first and then other balls before anything sinks or collides with one of the 6 pockets. The only thing I can come up with is nested if/then statements. Beyond that, every time I try to implement anything, I am lost with as to how.

Thank you for the correction regarding the generic collision event duplication.
I have confirmed it with a logging procedure.
Log







blocks (6)



The Original Post question requires the addition of Ball lists for

  • Balls that must be sunk before the eight ball
  • Balls that have already been sunk
  • Balls that remain unsunk before the eight may be sunk

The problem with the generic collision duplication problem requires more thought, perhaps deferring action on collision to a Collision Cop Timer event, firing a few milliseconds after colliding components have done the paperwork to log their collisions in a collision table ((Ball1,Ball2), (Ball2,Ball1), (Ball2,Ball3),...) to enforce Newton's Laws of conservation of energy and momentum.

1 Like

Regarding the generic collision duplication problem, here is a technique to avoid doing the same collision twice...

Keep a list of all the possible things that could collide. (Balls and Holes in this case.)

When a Collision Event is triggered for a component and other component, look up the indices in that list of the two components, and compare them.

Only process a collision between two components if they are in ascending order in the list.

That would eliminate half the collision events while still processing each possible collision just once.

To get a bounce calculation of two equal balls regardless of direction and speed of either ball, see
https://pressbooks.bccampus.ca/physics0312chooge/chapter/8-6-collisions-of-point-masses-in-two-dimensions/

1 Like

I have made a similar pool game several year ago, here is how two balls exchange speed and direction:

1 Like

The @kevinkun collision procedure is better than the collision handling in my sample, since I only addressed collisions with stationary balls and his procedure (if I read it right) should handle collisions involving two moving balls, with preservation of both energy and momentum.

If you have not yet noticed, you can drag code from this thread directly into your Blocks Editor Workspace.

I forgot to mention one last thing about the Original Post's code.

Do not call the reset procedure immediately after the user does something that ends his game.

Notify the user (if he has not had a chance to notice it himself), but leave it only up the the reset button to call the reset procedure.

Otherwise, you deprive the player of necessary game feedback.

yes if two balls have same mass.

2 Likes

Combining all the above, here are the critical parts:



Sorry, no .aia file for school assignments!

P.S. Remove all the other collision events for individual balls. This covers all collisions.

1 Like

Do you have any issue that the balls collided just bypass each other, with no change of their speed/direction?
If the speed is very fast, or radius of ball very small.

I didn't get to test for that. I had trouble getting a good swipe for the cue ball using the OP project code . I just checked for bounce a few times.

I can envision missing collision if the ball jumps forward more than its diameter.

Thanks for all your help, some of it is a little over my head at the moment but It gave me a better idea.

I am not swiping it, but draw a line ( as pool cue) from the cue ball to touch point when dragged, it's length(as the strength), and angle determine how the cue ball moves.

Yes, I used a pool cue stick sprite in my own project and doc. I should get to around to refurbishing it for generic events.

Btw the dual movement parameters speed and interval add a quantum quality to collisions, like in semiconductor charge barrier leaping.