Sign in to follow this  

Handling collisions

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

I'm sure I have no clue what I'm doing since I've just started, but I'm trying to make a kind of barebones game engine. I want to make one because I hate the thought of hard coding things that may need to be changed and because I want a reusable system. So far, I have a "world" class to manage and update all my game entities by calling each entity's Update() method and other relevant methods. The "World" class also checks for collisions between entities. Right now I'm trying to determine how to handle collisions behavior. After I've determined that 2 entities have collided, I'm not sure how to determine what action each entity should take. Obviously, each entity needs to know what its colliding into, except knowing specifically seems like it would take a lot of extra information and coding. So, it seems like some general information might do like if the opposing entity was a "bullet" or a "spiked platform". If you were comparing the player's character to an entity, it would get more complicated since entity states would matter. A player's entity would have to be "attacking" for an enemy entity to take damage. So mainly, I'm wondering what data needs to be tracked for handling collisions and how a handleCollision() method should be written in order to be flexible enough to handle colliding with different types of entities like blocks or enemies and handle different actions from entities like attacking or defending. It would be nice if I could write it to determine collision actions based on the other entity's type and state, though.

Share this post


Link to post
Share on other sites
It all depends on what kind of game you intend to do. E.g. for a tetris type game you need different information as in an action game. Don't worry to much to get it perfect the first time. A good article you might want to read is this: http://scientificninja.com/advice/write-games-not-engines.

Other than that I would store for each frame all occuring collisions in a queue together with the following information (e.g. void QueueEvent (...) )

  • which entities collided (probably just pointers to the entities or their ids)

  • when did the collision occur

  • at which point did the collisions occur


and work through the queue once the simulation has finished (e.g. void ProcessEvents (...) ). All further information (such as the type, state, etc.) can then be queried when its needed in ProcessEvents ().

Cheers,
fng

Share this post


Link to post
Share on other sites

This topic is 3147 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this