Search code examples
c#collision-detection

How to make this collision detection algorithm account for all the objects at once?


Okay, so I'm trying to make a game that uses this algorithm: http://www.codeproject.com/Articles/15573/2D-Polygon-Collision-Detection

But I need it to calculate all the objects that could be colliding with the player object, not just one at a time. How can I do this? Or do I need to use another algorithm? Cause this one pushes you into a wall if you're between two walls.


Solution

  • Detecting collisions and resolving collisions are 2 separate steps. Algorithm you've mentioned detects collisions, nothing stops you to use it to detect collisions with all objects you are interested in.

    Resolving collisions is more interesting process as you need to decide what each collision actually means - i.e. collision with arrow and collision with wall should cause different effects. Resolving multiple collisions (i.e. as you've mentioned "object in the corner/narrow tunnel") may require some creativity - i.e. you may have to violate what your physics calculations say and move object in some reasonable state.

    One simple thing that may work is to avoid multiple collisions by making time steps much smaller. You still will run into "object in a corner" cases, but less often and may be able to have simple workarounds.