Sign in to follow this  
jamesl22

2D Sidescroller and collisions

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:
[code] if (isColliding(object[0], object[i]))
{

BoundingBox test;

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

}
[/code]
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
[quote name='James Lovejoy' timestamp='1317676259' post='4868705']
What method would I use to stop this and to implement ramps etc. Preferably with examples please.
[/quote]

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:
[url="http://chrishecker.com/Rigid_Body_Dynamics#Physics_Articles"]http://chrishecker.c...hysics_Articles[/url]

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this