problems with collision algorithm
Loki66

Hi everybody
I have been trying to make two circles that move and collide with each other and with the edges of the display.
the rebound algorithm is ok, but the collision algorithm is not
I searched on many sites and the result is that I can't get anything to work.
does anyone have a collision and bounce algorithm that works?
attached is the program crap I made. if you want to try it?
thank you all

Edgar Reynaldo

I will try your program when I get time.

Elias

The easiest way to do this may be to use a third-party library like Chipmunk or Box2D. They are completely free to use like Allegro and already solve this (surprisingly involving) problem - and they likely solve it in a way that's way more performant than what any of us could come up with from scratch (you can have 1000ds of circles collide with no problem at all).

They also provide a lot more things but you can just ignore those (that's how I used Chipmunk before myself, just circle-circle and circle-line collision). You can also read their source code and just steal the algorithm - the license allows it :)

Thread #617957. Printed from Allegro.cc