Simple 2D collision response
I'm making a 2D side-scrolling platform game and have just about completed the engine except for one aspect. For certain "interactive" tiles, like moving platforms, I have decided to make them regular sprites instead of putting them in the tile array (which allows for it to move, animate, etc. easier since it is using the same moving/animation functions the other sprites are using). However, while the collision detection itself works fine, the problem is the response (or, more accurately, the correction of the sprite's location). All I want to do is correct the player sprite's location so that it's not overlapping with the interactive tile sprite anymore. I tried to detect which side the player is hitting (I'm using bounding boxes) as a basis for what direction the player should be corrected to, but it seems like all collisions are being swallowed up by the check for left-side collisions.
I have been using simple pixel-comparisons up until this point (along the lines of if (sprite1->GetX() < sprite2->GetX() + sprite2->GetWidth()), but with some added things to make sure the bounding boxes are accounted for). Is there any easy, reliable way to find out where the sprite is hitting another sprite based on collision boxes?
I have been using simple pixel-comparisons up until this point (along the lines of if (sprite1->GetX() < sprite2->GetX() + sprite2->GetWidth()), but with some added things to make sure the bounding boxes are accounted for). Is there any easy, reliable way to find out where the sprite is hitting another sprite based on collision boxes?
What you need to do is find the minimum separating distance. This is really easy for AABBs. For each direction (up, down, left, right) find the minimum distance that you would need to push the objects to make them separate. I could elaborate after I get off of work.
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Collision Response | merrill541 | 7 | 3,370 |
Nov 8, 2008 09:14 PM Last Post: merrill541 |
|
| Edge Collision Response Problem | Bachus | 9 | 5,536 |
Mar 21, 2008 03:34 PM Last Post: Skorche |
|
| Collision Response With Circles | Nick | 8 | 3,281 |
Nov 3, 2006 04:11 PM Last Post: Skorche |
|
| Collision Response Question | blobbo | 30 | 11,010 |
Oct 10, 2005 05:19 PM Last Post: Andrew |
|
| Help required with Math of Collision Detection/Response | blobbo | 7 | 4,043 |
May 6, 2005 02:38 PM Last Post: DoG |
|

