2D collisions between objects.

Started by
0 comments, last by Eelco 18 years, 1 month ago
Hi. I am making an algorithm for collisions between two objects, whose boundaries are delimited by a rectangle (AABB). Now, I was thinking each object should handle his collisions how he sees fit. So he receives a message that he collided and who he collided with. My question arises on the following example. Rhino 1 is going left, velocity is x=-1 y=0, and Rhino 2 is going right, velocity is x=1 y=0. I want each rhino to change to a random direction(except the current one) when they collide. What happens is that i'm making each Rhino advance till they overlap, and on the OnCollisionMessage(sender, receiver) event i get what direction they were facing, and I substract the velocity before changing the direction. Rhino 1 would first add 1 to Rhino1.X and then choose a random direction. Rhino 2 would decrease Rhino2.X by 1 and then choose the direction. What happens is that if i have several other objects on the map, this scheme is totally messed up, since on one side there could be an overlapping object, and then when substracting the velocity to the position, the new position overlaps with the other object, making it impossible to fix. If you don't understand this, i could post a pic. Either way, do you have any suggestion as how to tackle this problem? Are the objects supposed to manage the collisions by themselves, or should there be an omnipotent class that will handle all collisions of objects and reposition them as it sees fit? I kinda reached a dead end and i'm clueless which way I should continue. Thanks in advance!
Advertisement
math and physics anyone?

either way, resolving interpenetrations is no trivial subject, and i doubt there is an answer that can be contained in a single forumthread.

an encompassing class handling this seems easier to me, but then again that could be my lack of OOP knowledge.

This topic is closed to new replies.

Advertisement