Raycast character controller: handling stairs

I’m currently working on a project that includes character movement similar to that in Roaming Ralph – the character is prevented from falling through the terrain by casting a ray downwards to find the height of the surface below it – and have hit a bit of a problem in steps and other such sudden changes in terrain-height.

The current strategy sets the character’s z-coordinate when the character is considered to be “on the ground” or found to be below the ground (so that falling and jumping aren’t interfered with).

Moving such a character onto a step thus results in the character instantly snapping up onto the surface rather than moving smoothly up to it, which is especially jarring in the case of the player’s first-person perspective.

I’ve tried placing a “smoothing node”, which used averaged positions stored over time to smooth out character positions, but became concerned about the effect of the incurred lag between input and response, and the potential discrepancy between the character’s apparent and logical positions.

I could model the collision geometry for stairs as ramps, but that seems a little unsatisfactory, and still leaves objects such as low tables.

Does anyone have any recommendations as to how to solve this problem? I imagine that this issue has been encountered before; how has it been solved in the past?

(While writing this I did think of using intervals to lerp the character’s position when a sudden vertical offset is detected, but that may still leave me either with a discrepancy between apparent and logical positions, as above, or with potential issues of other colliders (used to keep the characters out of walls and the like) hitting the step as they lerp…)

There are few ways I’ve seen video games handle “stair physics”.

  1. The “rough” way, when the collision geometry of stairs is like real stairs and the character moves up and down the stairs there is that unwanted fast snapping you don’t want.
    Some games doing this still use ramp geometry for stairs for the camera, but not the player. That is why the camera doesn’t go crazy with the character.

  2. Most games use the “ramp” method you mentioned. The collision geometry of the stairway is an ordinary ramp and it can be over the stairs or a little “intersecting”. Both have unwanted effects. With the first your character appears to be slightly floating in air, but his feet never interesect the visible geometry. With the latter your character seems less like a ghost but the player might see his feet going “inside” the visible stairs geometry.

  3. Third method uses ramps also, but this time your character can only go straight up or down when he reaches the stairway, no right and left. There is also a quick transition animation to position the player exactly where you need him for the animations to look perfect.
    Whit well made animations this method looks pretty good.

  4. IK/FK physics for feet. You again use ramps for moving the whole player, but not for his feet. Don’t know much about this one.

Thank you very much for your reply. :slight_smile:

In my case I probably won’t have a player character model to worry about (the game is viewed from a first-person perspective, and I don’t mind the player not being able to see themselves; for story-related reasons mirrors may not be an issue), but my chosen method will presumably affect NPCs.

I really don’t like the effect of suddenly snapping up a level, so I’ll discard that option for the moment.

From your descriptions, I think that the “ramp” method is probably my best bet. Tables and the like might be issues, but I think that a solution might be found between canned animations for NPCs and some ideas that I have for the player (likely either some sort of steep ramp at the edges or requiring a small jump to mount them).

(I could go for an IK/FK solution, but I doubt that either would significantly impact the gameplay aside from increased immersion – which should be partially solved for NPCs by the canned animations mentioned above – and isn’t a field that I’m terribly familiar with, thus potentially calling for a noticeable spike in development time.)

Thank you again. :slight_smile:

Another solution might by partial ramps, making every step of the stairs a small ramp:


This way it wont be sudden jumps for the camera, but you do get the stair feeling. You could also make small tables some sort of traperzoid and combine this with making the player slide down from a too steep ramp. This way when the player is only ‘half-way’ up the table he will slide back down. Else it seems like the player is floating in mid air.

Adding some sort of camera walk animation (making the camera wobble up/down left/right with the steps of the player) will probably add up nicely; this would conceil the ramps and the sliding down. If you have this, one big ramp for stairs might be sufficient as the player will barely be able to notice the seperate steps through all the camera movement.

That may well be worth trying, thank you. :slight_smile:

(Indeed, I have something like this in mind for the tables, but for whatever reason it hadn’t occurred to me to extend this to the stairs. ^^; )

I am, I’ll confess, a little concerned about the potential loss of player control while “sliding” down the ramps (and such sliding is a feature that I intend to have for other surfaces, such as actual steep slopes), especially in the case of stairs; in terms of gameplay I have a suspicion that the ramp will likely “feel” better.

On the other hand, perhaps some camera-height/collider-size adjustment might allow for a stair-like feel for the player on staircases; it’s worth thinking about, at least.