Sign in to follow this  
AdvsNoob

Best way for 2D platform collision?

Recommended Posts

Well i know that. But what is the best method to use to do this?
Check each axis of the two rectangles to see if either overlap. If so, separate by either the minimum axis of overlap or by some heuristic based on the direction of travel.

This is pretty simple, what exactly are you having trouble with detecting and resolving axis-aligned rectangles?

Share this post


Link to post
Share on other sites
Well i know that. But what is the best method to use to do this?
Check each axis of the two rectangles to see if either overlap. If so, separate by either the minimum axis of overlap or by some heuristic based on the direction of travel.

This is pretty simple, what exactly are you having trouble with detecting and resolving axis-aligned rectangles?

 

 

We got the rectangles working now its just making the player stay on top of the block. I currently have it reset the Y position of the player to a constant part of the map but how can I get it so the players position will be set to the top of the block?

Share this post


Link to post
Share on other sites
Or just set the y position of the player to be equal to the top of the block it is standing on minus the height of the player block.

It can be helpful in a simple, AABB based tile physics system to do your x and y modifications to your player's position individually. If you first move the player by its y velocity, if you intersect with a block after this move, you know from the direction of the y velocity whether to move the player to either sit on top of or be directly under the block.

If you then do the same with the x, again using the direction of the x velocity to determine which side of a block to align the player with in the case of intersection, you get a very solid, sliding physics that is suitable for simple games.

All this goes out the window if you want to use anything other than AABBs, but sounds like that is a long way off.

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