• FEATURED
• FEATURED
• FEATURED
• FEATURED
• FEATURED

View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# Best way for 2D platform collision?

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

11 replies to this topic

Posted 31 December 2012 - 04:33 AM

I am trying to think of what the best way for collision in my platform game should be. My friend and I cant really decide on how to approach it as well. Any ideas?

### #2pulo  Members

Posted 31 December 2012 - 06:06 AM

Easiest way would be making it tile-based. So the collisions are just simple rectangle intersections.

Posted 01 January 2013 - 06:07 AM

Easiest way would be making it tile-based. So the collisions are just simple rectangle intersections.

Well i know that But what is the best method to use to do this?

### #4Morphex  Members

Posted 01 January 2013 - 05:39 PM

If you can wait a few days, I am currently writing a article in 2D collision, SAT implementation etc. So it might prove usefull.

Check out my new blog: Morphexe

### #5Aardvajk  Members

Posted 01 January 2013 - 07:12 PM

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?

Posted 02 January 2013 - 02:59 AM

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?

### #7pulo  Members

Posted 02 January 2013 - 07:47 AM

Calculate the depth of the intersection and then add or subtract it from the y position of the player.

### #8Aardvajk  Members

Posted 02 January 2013 - 04:13 PM

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.

Posted 02 January 2013 - 11:27 PM

Collision works now, but when the player is standing on a tile and lets say a tile is on his right and he is touching it. He cant jump up.

### #10Morphex  Members

Posted 02 January 2013 - 11:29 PM

You need to check if the collision is happening below, or to the sides of the player.

Check out my new blog: Morphexe

### #11Stuntdk  Members

Posted 03 January 2013 - 12:06 AM

You could take a look at the XNA Platformer starter kit, perhaps you could get some inspiration from that.<br />http://msdn.microsoft.com/en-us/library/dd254918%28v=xnagamestudio.31%29.aspx

Posted 03 January 2013 - 12:23 AM

You could take a look at the XNA Platformer starter kit, perhaps you could get some inspiration from that.<br />http://msdn.microsoft.com/en-us/library/dd254918%28v=xnagamestudio.31%29.aspx

We got it working! YEAHHH! Thanks everyone!

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.