Jump to content
• Advertisement

# 2D collisions between objects.

This topic is 4674 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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!

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
Rutin
19
3. 3
4. 4
khawk
15
5. 5
A4L
13
• Advertisement

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633743
• Total Posts
3013644
×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!