# How to determine if character has fallen into the gap in an infinite runner/jumper?

I'm building a 2D infinite runner. In the game, character jumps from pillar to pillar and pillars are randomly generated. I have this working. But how to determine if the character failed to jump on to a pillar and has fallen into the gap between pillars? A pillar is ordinary rectangular in shape.

• OT: I though this question was posted on rpg.SE and I thought "What kind of rule exploit has been found now? Infinite running how?" – o0'. Apr 16 '15 at 20:08

Add a rectangular region at the bottom of the level, lower than the minimum allowable height of a platform. If the player has intersected this region, they have fallen off a platform.

• And make this rectangle a child of camera so it's moving with camera and is always present? That's so easy. Thanks. – SanSolo Apr 15 '15 at 14:57
• Even if the player shouldn't be able to fall through the level, I think this is a good safeguard to have if he somehow manages to. – mucaho Apr 16 '15 at 0:00
• If you're literally checking intersection, make sure that your character can't fall so fast as to clip through the surface (i.e., one from the character's entirely above, and the next frame entirely below). – wchargin Apr 16 '15 at 14:13
• Yes, the rect should extend as far down as necessary to avoid this. Also just checking the height will work, but this gives you the flexibility of resizing the "kill region" depending on the level. – mklingen Apr 16 '15 at 19:07
• To avoid "clipping" through the rectangle, why not a simple if (playerPos.x < minHeight)? – Cole Johnson Apr 17 '15 at 5:26

If your game only scrolls horizontally, you could check whether the vertical position of the character is below the lower edge of the stage.

If your game scrolls vertically as well (probably upward), you could check whether the player has fallen below the bottom edge of the view (i.e. the area of the stage that is onscreen, or in focus of the camera).

In general, the death condition is if the character fails to remain "in camera". By controlling the movement of your camera, you'll be able to tune your gameplay. For example, if in a vertical scrolling stage you only allow your camera to "rubberband" a little bit downward, while allowing full upward motion, you will penalize deep, offscreen falls.

• Yes, that's an easy way too. I'd just need to find out lowest position.y that the character can be. – SanSolo Apr 15 '15 at 15:00
• Correct! in case of a horizontal scroller you could simply check the vertical size of the stage in your map editor. In case of a vertical scroller, you could make sure the camera only moves upward. That way, if the character falls down, he'll end up below the view of the camera. You can then simply check if the character's vertical position falls below the bottom boundary of the view. – Jelle van Campen Apr 15 '15 at 15:24
• @JellevanCampen: You don't have to limit the camera to upward movement necessarily. You can kill characters who fail to remain "in camera", or have the camera follow them around. – Mooing Duck Apr 15 '15 at 22:19
• I don't like this answer as much because it ties the camera directly to level boundaries. mklingen's answer works even if the bounds of the level are more than one screen height in size. The camera can move up and down to focus on the character, but there's no risk that the character will fall faster than the camera, stay in the level, but still collide with the boundary box attached directly to the camera. – Kevin - Reinstate Monica Apr 16 '15 at 0:30
• @Kevin: I agree for general games, but not for procedurally generated infinite scrollers. For example, in a vertical scrollers, you would have to either keep on spawning new boxes and despawn offscreen boxes, or you would have to keep updating the boxes as the camera moves around. As the death condition is directly tied to "failing to remain in camera", it makes sense to tie the condition to the camera. It also also more performant to do a camera boundary check, rather than to spawn new objects and resort to collision checking. – Jelle van Campen Apr 17 '15 at 11:24

Alternatively to checking the vertical coordinate, you could just check the vertical velocity. If the character is falling down faster than some threshold, conclude they're dead (even if there is some platform low enough to still reach, the impact would be fatal).

Of course, this only works if your game properly implements basic free-fall physics, i.e. the downwards velocity actually increases during the fall, as it does in reality (up until terminal velocity).

If you have height of pillars, you can find lowest existing, and compare it to vertical position of player. If he is below lowest pillar, there is no chance he can get back. You can limit this check only to pillars behind and in front of player.

Example: We have 3 pillars, with heights [10, 20, 40]. Player jumped is on pillar with height 40, he jumps forward to 20. He felt in gap between 40 and 20, he's now at height 15. That means he felt. For less strict check, wait till he is below 10.

• All pillars are same size. It's the horizontal gap between two pillars that varies :) – SanSolo Apr 18 '15 at 8:19

Keep a count of how long a character has fallen. (i.e. how long they've been moving "down"). Once they've fallen more than a screenful of time, they by definition have fallen off the stage, yes?