Jump to content
  • Advertisement
Sign in to follow this  
elurahu

Gamelogic handling of collisions (design)

This topic is 3683 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

In the last few days there's been a few different topics on how to handle collisions. They've made me question how I did mine and I would love to get some input on how they possibly could be done. Mind you I'm talking about the high-level collision events (bullet hits player. The collision spawns a bloodsplatter particle system, decreases hitpoints and increases score). The way my engine is constructed the collision events come in callback form. All of these callbacks happen while the physics simulation is running. Whenever I get a callback the data I need is buffered and stored for later processing. As soon as the main game logic update loop starts running the buffered data is parsed. The collision pairs are type checked and the appropriate functions are called.
foreach pair in bufferedData
    if (pair.obj1 is player && pair.obj2 is bullet)
         BulletPlayerHandling(pair.obj1, pair.obj2);


The above snippet is grossly oversimplified but in essence this is what I do. Problem with this is the collision handling have a very high coupling and very low coherence with the data it works on. The other thing this scales extremely badly since I would need n*(n-1) / 2 methods for n different objects (I think :)). After reading one of the other threads regarding this issue I see the advantages of using a visitation pattern to solve this problem. My problem is however how to handle to stuff that in the chosen example have no relations to either of the colliding objects. Namely stuff like score and particle systems (OK psystems might be doable).
pair.obj1.collideWith(pair.obj2);
pair.obj2.collideWith(pair.obj1);


I've just implemented a multicast delegate construct like the one we know from C# that I could use as well. However it seams like a lot of overhead to raise an event on each and every objects that have collided.
pair.obj1.onCollide(pair.obj2);
pair.obj2.onCollide(pair.obj1);


Basicly what I'm looking for is a better way to solve the above problem. - How to cleverly use a list of collision pairs to handle game logic. - How to make sure you're able to handle both one-time event and individual handling of each colliding object. I hope the above makes sense. I have a tendency to start rambling when I have to explain what I've implemented. And I really hope someone is able to help me out! Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!