Public Group

# Super Mario Style Game - Tile Collision Problems

This topic is 3045 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to write a platform game in a similar style to Super Mario. I'm currently having an issue with regards to my collision detection method used in my game.

Currently, I am employing an approach similar to the one described here :
N Tutorial A

Essentially, every frame, I check my character's bounding box to see if he intersects with any tile in the game world. If he does so, I proceed to calculate the projection vector of the overlap, IE how much he is intersecting a tile by. I then push him out in the relevant direction to prevent him from overlapping any tile.

Unfortunately, I seem to experience problems when my character is moving horizontally. At the moment, I apply a Y velocity to my character at all times. This is so that if he walks off a platform, he begins to fall.

The problem I am experiencing is that when I check all tiles for intersection, I am returned a tile below my character (IE the tile he is walking on). This is because of the vertical velocity being applied to my character via gravity. However, I only ever return one tile so this could well be my problem... perhaps I need to iterate through all the tiles my character is colliding with, and only process the tile with which I am colliding with the most (IE have intersected the most)?

I can think of a number of other solutions to the problem, but all of the ideas I've come up with don't seem to work.

Any help would be most appreciated!

[Edited by - the_golden_gunman on July 20, 2010 12:09:24 PM]

##### Share on other sites
Quote:
 The problem I am experiencing is that when I check all tiles for intersection, I am returned a tile below my character (IE the tile he is walking on). This is because of the vertical velocity being applied to my character via gravity.

So check for left/right collisions *before* the vertical velocity is applied.

-----
BTW, the approach I use is to turn gravity on only when there is nothing below the player, that is, when there is no collision at (player.x, player.y+1). That way there's no pulling force while the player is standing on something, and it is much easier to check for left/right movement as the player is not actually colliding with the block below.

Take a look at the Game Maker platformer tutorial (yes, game maker...). As much as people seem to hate it, there is stuff to be learned from those tutorials and it's shown in such a simple way that it's easy to translate to whatever language/library you're working in.

##### Share on other sites
Quote:
 perhaps I need to iterate through all the tiles my character is colliding with, and only process the tile with which I am colliding with the most (IE have intersected the most)?

Is there a particular reason you want to restrict the collision detection and response to a single collision?

As outlined in the N tutorial you reference, it might work better for you if you
Quote:
 (2) determine collision results for each pair identified in step (1) (narrow phase).

In the case you mention, the player has a tile both in a horizontal direction and a vertical direction, process both collisions.

##### Share on other sites
Thanks for the replies. I'll now implement the collision code with collisions across both axis of movement.

1. 1
Rutin
73
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• ### Forum Statistics

• Total Topics
633425
• Total Posts
3011810
• ### Who's Online (See full list)

There are no registered users currently online

×