• Advertisement
Sign in to follow this  

2D Sidescroller and collisions

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

Hi,

I am writing a simple 2D sidescroller in C++. I have AABB collision detection all working great. Unfortunately it's just a simple "two boxes intersecting, move back to where we were before". This means that there are no ramps and the player can get stuck on things if they hold down the arrow keys. What method would I use to stop this and to implement ramps etc. Preferably with examples please.

I have tried the following:
if (isColliding(object[0], object))
{

BoundingBox test;

test.x = prevX, test.y = currentY, test.width = object[0].width, test.height = object[0].height;
if(!isColliding(test, object))
{
currentX = prevX;
return true;
}
else
{
currentY = prevY;
return true;
}

}

However, collisions on the Y axis work but only sometimes on the X. E.g one side of the square but not the other...

Thanks,

James

Share this post


Link to post
Share on other sites
Advertisement

What method would I use to stop this and to implement ramps etc. Preferably with examples please.


Separating Axis Theorem would solve most of your problems.

Best articles around are Here:http://physics.hardwire.cz/index.php?action=show&sortby=order&parent_id=36
I Highly recommend Oliii's SAT article.

Once you have One of the narrow-phase collision detection methods implemented, dynamics would be the next step.
in my experience, there is no one book or article that will help you with this. I had to read a couple of books and a lot of articles,some of the math i didn't fully understand. Eventually i was able to pull all the information together to make something close to dynamics seen in other 2D physics engine.

Here are a series of physics articles to get you started once you implement a narrow phase collision method:
http://chrishecker.c...hysics_Articles

Once again, this is not the best resource for physics but it might be a good start.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement