# Make the player run onto stairs smoothly

I have a 2D Platform game, where the player Always runs to the right, but the terrain isn't Always horizontal. Example:

I implemented a bounding-box collision system that just checks for intersections with player box and the other blocks, to stop player from running if you encounter a big block, so that you have to jump, but when I put stairs, I want him to run smoothly just like he is on the horizontal ground. With the collision system you have to jump the stairs in order to pass them!

I thought about generating a line between the edges of the stairs, and imposing the player movement on that line... What do you think? Is there something more clever to do?

If you're able to rotate the boundingboxes, I would've put a 45 degree rotated box at the player's feet and combine it with one non-rotated box to represent the rest of the body. That could make the player automatically slide over anything small enough.

Though, that would probably cause some clipping with the player model and the stairs.

Another idea is to put one boundingboxes from the character's head to kness with higher width than the box of the character.

When the player collides with something which the box 'A' does not, you can move the player ontop of what it collided with

_________________
|    |     |    |
|    |     |    |
|  A | pla | A  |
|____| yer |____|
|     | _________________________ <- step
|     | |
--------------------------------------------- <- ground


There are three general approaches to dealing with stairs in video games:

The "Mario" approach is that you must jump to get up stairs.

The "Castlevania" approach is that moving up/down stairs is a different sort of movement; you must press 'up' on the controller, and a special "stair-climbing" animation is played to traverse the stairs. A variant of this is the "Resident Evil" approach, where moving up/down stairs is treated as a complete cutscene that plays when the player presses an interaction button; no interactive stair-climbing is permitted whatsoever.

The "Almost Everyone Else" approach is the one that you mentioned: treat the stairs as if they were actually a ramp. Depending on what sort of game it is, you may wish to place the ramp at different heights relative to the stairs. Typically in a 2D game, the "the stairs are actually a ramp" trick is less noticeable to the player if the ramp is level with the bottom corners of each stair step, while in a 3D game it's typically less noticeable if the ramp is level with the top corners of each step. (as in a 2D game it's easier to notice if a character's feet are floating above the ground, and so you want to minimise that, whereas in a 3D game it's easier to notice if a character's feet are clipping through the ground, and so you want to minimise that).

• Great remark on float/clipping on different graphical standpoints. – Kroltan May 11 '14 at 10:20
• Your information is quite a bit wrong. Only in the old mario games you have to jump to get up stairs. But I guess that's obvious. But resident evil definitely also had stairs that can be climbed interactively! – Tara May 17 '15 at 16:54

Most of the methods I've encountered have already been stated above -- but there's still one more that hasn't been mentioned. When the player encounters a vertical obstacle that's short enough (say, 1/3 their hight), simply put them on the top. Minecraft and the Source engine for example take this approach in that kind of situation. Additionally, this method allows you to still use pure AABB for all of the physics while not putting the player through the pain of constantly having to jump up stairs.

• Would be nice if you could explain how to detect such obstacles. – Tara May 18 '15 at 11:13

I'm currently working on a similar part of an engine, and the way I dealt with stairs/slopes is by counting the transparent pixels in my ramp texture and offsetting the player's object by the amount found.

It is similar to the idea of the height map that is detailed in this article: http://info.sonicretro.org/SPG:Solid_Tiles#Slopes_And_Curves

I imagine that's really what you would be looking to do, and you can choose to play a different animation that plays according to the ascension of the stairs.

There is also a good overview of the different slope concepts in this article: http://higherorderfun.com/blog/2012/05/20/the-guide-to-implementing-2d-platformers/