Jump to content
  • Advertisement
Sign in to follow this  

2D Collision Detection and Response

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

Hey guys,

I wondered if someone would be able to help point me in the right direction for working out collisions in a simple 2D engine I'm putting together.

I have a basic 2D tile grid, and tiles can either be on or off.

What I want to do is allow the user to drag tiles around freely and have them snap back to the grid on release.

But the issue I'm having is with multiple tile collisions, I wondered if someone could provide a pseudo explanation of how I should be calculating my collisions and responses?

At the moment I have in my game loop:
  • Update positions
  • Test for collision and reposition when colliding
    Am I needing to separate my detection from my response?

    And should I be accumulating my repositioning vectors and then applying them at the end?

    Many thanks.


Share this post

Link to post
Share on other sites
What do you mean by "repositioning"? Do you move objects away from where they are colliding? Normal physical engines compute forces (and torques), which are then turned into accelerations (and angular accelerations), which are integrated to update object positions in discrete steps (possibly also computing velocities and angular velocities).
Simultaneous collisions are handled correctly if processing either one before the other produces the same final result (the common limit of decreasing time of impact differences of both signs).

Share this post

Link to post
Share on other sites
Don't listen to Lorenzo -- directly correcting the objects' positions when a collision occurs is a standard solution that's used in many tile-based platformers (e.g Mario).

Summing the correction into a single vector and then applying it at the end won't work, you need to iteratively adjust the position of the object with each collision.
If your engine supports sloping non-square tiles, then objects might get stuck in a "V"-shaped region where the correction from one tile pushes the object into collision with another tile.

The source code in this tutorial deals with collision with multiple tiles, it might help: http://www.metanetsoftware.com/technique/tutorialB.html

Share this post

Link to post
Share on other sites
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!