Jump to content
  • Advertisement
Sign in to follow this  

2d rectangle colision, figuring out what comes from where.

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

I am currently designing a platformer. The arch enemy of my existence (next to onions), collision detection has once again come to attack me. My method can detect and act on collisions from the left, right, and bottom, correctly. My problem is differentiating collisions from the top from the rest. Note: My current method evaluates the following if an overlap is detected. Projected values are where the player will be should we move him. Note: It is also worth mention that I am using SDL, so my coords are the top left of the given object, greater means further down and less than means further up than. Anyways, my method: If we will hit the left side //If our projected right X is greater the the objects X AND //If our projected bottom Y is greater than the objects top AND //If our projected Y is less than the objects bottom AND //If the player is heading right If we will hit the right side //If our projected X is greater the the objects left X AND //If our projected Y bottom is greater than the objects top Y //If our projected Y is less than the objects bototm //If our player is heading left. If we will hit the bottom //If projected Y is less than objects Y bottom. //If we are jumping These work, I can run into any of them and it does what it should. My problem now is finding out if it is falling on the top. Whenever I check for it, other conditions match and it executes that one. What conditions are unique to it hitting the the top? I have been wrestling with this for about one week and three rewrites.

Share this post


Link to post
Share on other sites
Advertisement
I think I'd use the positions from the previous frame somewhere in the calculations. If in the previous frame the player was above the box, and after updating the positions the player is overlapping the box, then the player must have collided with the top of the box.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!