Jump to content
  • Advertisement
Sign in to follow this  
Uphoreum

2D Wall Collision Detection

This topic is 3710 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 have a 2D map made up of a grid of rectangles which make up the walls. You can move around and basically, if you collide with a section of wall, it moves you back to the position you were in before you collided and sets your velocity to zero. The problem with this is that you get stuck on the walls a little bit. I'd rather have it so that you can slide along the walls. I'm not really sure how to go about doing this. Can anyone help explain I might do it?

Share this post


Link to post
Share on other sites
Advertisement
This is actually simple. what you want to do is, before moving the character, find the point of intersection in which the wall and the object will touch, and or use a depth of penetration prior to displaying on screen.

Share this post


Link to post
Share on other sites
One way to make it easier is to move X and Y seperately. So like you add X velocity, check if you hit something, if so, back up so you're not hitting it. Then repeat but moving vertically. Easier than calculating an intersection point when moving along a diagonal line, and makes very little difference in the result, unless your characters move extremely fast.

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!