Jump to content
  • Advertisement
Sign in to follow this  
WhenWorldsCollide

2d smooth scrolling collision, how? help please!

This topic is 5111 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 smooth scrolling with tiles down, but I am unable to get collision detection working properly. What are some techniques for simple collision detection in a 2d game that uses smooth scrolling? Eventually, the game will be a side scroller like the Megaman series. It doesn't have to be the most efficient, just ANY simple technique so that I know when the sprite collided with something. Thanks. Edit: I am using SDL and I need a portable method, I can not use IntersectRect()

Share this post


Link to post
Share on other sites
Advertisement
I'd recommend AABBs (axis-aligned bounding boxes) or circles.

Static collision between two circles involves comparing the (usually squared) distance between their centers to the sum of their (usually squared) radii. With this information you can get the distance needed to push the objects apart so that they will no longer be intersecting.

AABBs can be tested with a simple separating axis test that involves only a few lines of code.

If you have quickly moving objects, you can look into sweep tests. Check the collision detection articles here on gamedev, google for it, or go to Dave Eberly's Magic Software site for code covering all sorts of intersections.

Share this post


Link to post
Share on other sites
the way i do basic colliosion is this ...

bool hitTest(int x, int y, int x2, int y2)
{

if(x > x2 - 5 && x + tileSize < x2 + tileSize + 5 && y > y2 - 5 && y + tileSize < y2 + tileSize + 5)
return true;

}

........

if(hitTest(xPos, yPos, enemX, enemY)==true)
//whatever code




That maight help you, but than again maybe not :P Depending on what kind of colliosion you want ;)

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!