Ball collision in pool game

Im trying to make a pool game in app inventor, but I don't know how to add collision to the balls. I found this document:

but I don't understand it.
Does anyone know of something easier to understand for a newbie? Thanks in advance.

You could try

I wrote it, and see the need to refurbish it.

Which parts in particular stank?

Thanks for the replay, I'm going to try it now. In the doc I was confused because of the variables, I didnt understand what I would add to them, but maybe I didn't look hard enough.

Thanks for the help I was able to get it to work. I noticed when the ball is collided with it seems like it doesn't bounce off the edge of the ball but the center of it. Do you know a way around this?

Thanks for your help.

The angles should not change between the two situations, but the overlap problem might be due to the interplay between speed and interval and radius.

Interval

The interval in milliseconds at which the Ball’s position is updated. For example, if the Interval is 50 and the Speed is 10, then the Ball will move 10 pixels every 50 milliseconds.

Speed

The speed at which the Ball moves. The Ball moves this many pixels every Interval milliseconds if Enabled is true.

I would try cutting both Speed and Interval in half, to see if that gives the Ball more frequent chances to respond to its environment.

Thanks!

Sorry to bother you again, but I am currently making an air hockey game for a school project. Whenever we hit the puck straight on it goes in the wrong direction almost always. Here is a video of it happening:
https://photos.app.goo.gl/oUbYXu5bmFpByjDu6 I'm guessing it's because the mallets are constantly moving, but I can't find a way around it. If you have a solution to this then will you please tell us because we are stuck. Thanks again.

Can't diagnose it without blocks.

Please download and post each of those event block(s)/procedures here ...
P.S. These blocks can be dragged directly into your Blocks Editor workspace.

See Download Block Images for a demo.

Make sure to include all collision and drag event blocks.






These are all the collision blocks. In the Twoballscollide procedure I did remove the speed part just so you know.

What is in your global balls list?

The mallet should not act like a free floating ball since you are holding it.

In my global balls list is ball1 ball2 and the puck. I have it set up kindove weird. I downloaded a extension so I could overlap blocks. I made a canvas for the top and for the bottom so the mallets would stop at halfway. I have another canvas where ball1, and ball2 follow malletball1 and malletball2 so they can collide with the puck. Do you think if I get rid of the extra layer it would fix the issue?

I thought in air hockey there is only the puck, and the two player mallets.

So what are ball1 and ball2 for?

I made a second layer so that it would only go halfway. The ball1 and Ball2 are invisible but the malletball1 and mallet ball2 are what you see

For Air Hockey, the mallet on puck collision should act like the collision of a pool cue stick with the white cue ball.

See this label in my doc:

It should be that simple, and you should not need any ball collision procedure since you don't have freely rolling balls, only the single puck.

Hey again, thanks for your help. I got rid of the procedure but have a issue with the headings. Although I found another issue. How can I set the heading of the mallets to the direction they are dragged?

You need a little trigonometry for this.

The drag event knows the starting and current X and Y values, right?

There is a math function atan2, that can take the change (-) in x and the change (-) in y and turn that into an angle.

Try using that angle as your heading and see what happens.

If I am trying to make a pool game, could I just use this or do I need more?

You can use

but it does not include

  • more balls (use Generic events)
  • pockets to catch the balls.
  • scoring
  • game management

You're on your own for those.

so I use that and just add more balls because I have everything else?