math question

Started by
6 comments, last by Yustme 16 years, 3 months ago
Hi, How do you hit a sphere with another sphere to make it go in a specific direction? I need to know this to be able to play against the computer with my game. For the record, it's a billiard game. Thanks in advance!
Advertisement
You did google the physics of billiards, correct?
EvanWeeks - Dad. Gamer. Developer.
Because in billards all of the spheres are on a level plane, we can think of them all as circles. To find out if two circles are colliding, you must check the distance between the two sphere's centers, and if that dist is less than or equal to the sum of the two circle's radii, then they are touching.

Bounding circles is easy, but making them bounce off of one another is a bit harder. You would have to apply some physics to it, using 2-dimensional collisions. I personally do not like doing those problems. You do need to have a basic understanding of momentum and kinetic energy of objects in order to solve those kinds of equations. Trigonometry also helps.

Read up on some tutorials on the internet, or if you have a physics book, go back and check on that stuff.

Good luck!
S. C. B.

Quote:Original post by EvanWeeks
You did google the physics of billiards, correct?



Hi EvanWeeks,

I have googled. But i haven't come a cross where they discuss the angle of impact on a sphere to make it go in a specific direction, or i over looked it.


Quote:Original post by sykosnakesix
Because in billards all of the spheres are on a level plane, we can think of them all as circles. To find out if two circles are colliding, you must check the distance between the two sphere's centers, and if that dist is less than or equal to the sum of the two circle's radii, then they are touching.

Bounding circles is easy, but making them bounce off of one another is a bit harder. You would have to apply some physics to it, using 2-dimensional collisions. I personally do not like doing those problems. You do need to have a basic understanding of momentum and kinetic energy of objects in order to solve those kinds of equations. Trigonometry also helps.

Read up on some tutorials on the internet, or if you have a physics book, go back and check on that stuff.

Good luck!
S. C. B.



Hi sykosnakesix,

I got a 3d engine and a physics engine in my game. The game is already playable.

But my problem is, how can i give the computer the same ability to win a game?

I can make the computer hit a sphere. But i don't know how to make it hit on a specific angle.
So, if I understand you correctly, you already have a working physics simulation where the billiard balls collide and react appropriately, and the problem you're having is how to have a computer-player aim on an appropriate angle to score? If so:

Work backwards from the result you want. For a given ballwith a known target pocket (or location if you want to move it but not sink it) calculate a straight line from the centre of the target location through the centre of the ball - where this line intersects with the side of the ball which is more distant from your target location is the point on that ball you need to have the cue-ball impact the target ball. Apologies for the incredibly poor graphic, but perhaps this will help you out a bit...


If you need to figure out which ball you want to hit, a simple method would be to simply perform these calculations for each possible ball, ruling out any for which the target shot cannot possibly be made, and then choosing one for which it is possible - bonus points for calculating where the cue-ball will end up and choosing one that has at least one possible "next shot". To make it a bit more fun you'd want to have the computer player not always be completely accurate.


Hope that's of some help...

- Jason Astle-Adams

Quote:Original post by jbadams
So, if I understand you correctly, you already have a working physics simulation where the billiard balls collide and react appropriately, and the problem you're having is how to have a computer-player aim on an appropriate angle to score? If so:

Work backwards from the result you want. For a given ballwith a known target pocket (or location if you want to move it but not sink it) calculate a straight line from the centre of the target location through the centre of the ball - where this line intersects with the side of the ball which is more distant from your target location is the point on that ball you need to have the cue-ball impact the target ball. Apologies for the incredibly poor graphic, but perhaps this will help you out a bit...


If you need to figure out which ball you want to hit, a simple method would be to simply perform these calculations for each possible ball, ruling out any for which the target shot cannot possibly be made, and then choosing one for which it is possible - bonus points for calculating where the cue-ball will end up and choosing one that has at least one possible "next shot". To make it a bit more fun you'd want to have the computer player not always be completely accurate.


Hope that's of some help...



Hi jbadams,

Thank you very much for your explanation!


Quote:Original post by jbadams
So, if I understand you correctly, you already have a working physics simulation where the billiard balls collide and react appropriately, and the problem you're having is how to have a computer-player aim on an appropriate angle to score? If so:



You understood me correctly.

No need to apologies for the graphic, its perfect!

It gave me a good idea how to get this done.

The game is more like a death match variant of the billiard game.

There are only 2 spheres in the game and the rules are simple. Try to make each other fall in one of the holes.

However, i do have a small question. Does it matter how hard the sphere impacts or not? I mean will this have an effect on the direction it suppose to move?

Thanks in advance!
Quote:Original post by Yustme
However, i do have a small question. Does it matter how hard the sphere impacts or not? I mean will this have an effect on the direction it suppose to move?
If your physics simulation includes friction then it may make a small difference, but you can probably safely assume this to be negligable. It will however of course effect how far the balls travel, which may have consequences if either of them bounce off the sides of the table, or if the chosen angle might cause the player's own ball to be sunk after impacting the other one.

- Jason Astle-Adams

Quote:Original post by jbadams
Quote:Original post by Yustme
However, i do have a small question. Does it matter how hard the sphere impacts or not? I mean will this have an effect on the direction it suppose to move?
If your physics simulation includes friction then it may make a small difference, but you can probably safely assume this to be negligable. It will however of course effect how far the balls travel, which may have consequences if either of them bounce off the sides of the table, or if the chosen angle might cause the player's own ball to be sunk after impacting the other one.



Hi jbadams,

The physics simulation does contain friction. I wanted to know this information for making the backtracking a little bit less accurate as a possibility.

Suppose the player's own ball falls in one of the holes. The opponent gets a point, that simple :P

Thank you very much for the info jbadams!

This topic is closed to new replies.

Advertisement