0
votes

I've choice to write a billiard game for class. All runs ok but I would like to improve realism to ball collisions.

For each ball I have a pygame rectangle, that means, ball center, ball diameter and position in game. And also a velocity vector (u_x, u_y).

At this time I check collision with colliderect, but I can change it measuring center balls distances.

I have read about Conservation of momentum equations but this not have ball positions in consideration. Is not the same two ball frontal impact than a lateral impact.

Someone can help to me in formula for new ball velocities after collision considering ball position at the impact moment. Thanks a lot!

1
@bart, thanks, but I dont understant dot, and boundary_normal. It is easy for you write python formula from this link?CrazyHorse
dot refers to the dot product and boundary_normal is the normal vector at the point of impact.Bart
oh! nice. I know how to calculate dot product, but, how can I take normal vector from my data? Thanks about your help, bart.CrazyHorse
bart, is a classical round billiard ball. You have center (x,y) and diameter (d) for both balls.CrazyHorse

1 Answers

1
votes

The module euclid will help. It contains a vector class, that has normal(), dot(), etc... http://partiallydisassembled.net/euclid.html ( You can copy the module into your project folder, without needing to install. )

For the formulas, check : https://gamedev.stackexchange.com/a/7901/6776 , or http://archive.ncsa.illinois.edu/Classes/MATH198/townsend/math.html#COLLISION

Note: the more complicated your physics become, the more you need to use a physics engine, such as [enter link description here][pymunk] or ODE. But, it is a good learning experience.