# 2D Collision Detection and Response

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

## 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.

-Stephen

##### 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 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

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633674
• Total Posts
3013277
×