Simple 2D collision response

Posts: 67
Joined: 2006.07
Post: #1
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?
Quote this message in a reply
Posts: 1,487
Joined: 2002.09
Post: #2
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.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Collision Response merrill541 7 5,297 Nov 8, 2008 09:14 PM
Last Post: merrill541
  Edge Collision Response Problem Bachus 9 9,811 Mar 21, 2008 03:34 PM
Last Post: Skorche
  Collision Response With Circles Nick 8 5,496 Nov 3, 2006 04:11 PM
Last Post: Skorche
  Collision Response Question blobbo 30 17,682 Oct 10, 2005 05:19 PM
Last Post: Andrew
  Help required with Math of Collision Detection/Response blobbo 7 5,907 May 6, 2005 02:38 PM
Last Post: DoG