Jumping
This article is a stub. You can help improve Game Design Novice by expanding it.

Jumping from a 2D platform game perspective, is nothing more than setting the vspeed to a negative number, temporarily overcoming gravity. Eventually, gravity will wear the negative vspeed down, and the game object will begin to fall.

To understand how jumping works, think about how you jump in real life. You first push off the ground, causing two forces, your force against the ground, and the ground pushing you up ( for every action there is an equal and opposite reaction). Then, after you are free from the ground, the upward force is weakened by gravity, slowing the upward momentum. Eventually, you stop and then accelerate as you fall back downward.

In game programming, physics are often simplified to make the job of programming the game easier. There is no need to simulate the force against the ground, so typically only the upward force is simulated by a negative vspeed.

Jump Flag

The jump flag is a flag variable used to determine whether or not a video game character can jump, and thus preventing double jumps (if not wanted) and mis-jumps. A variation on the jump flag is used in almost every 2D platform game.

Being flag variable, it has only two states 0 and 1. If the video game character is in the air, or otherwise cannot jump, the jump flag is set to 0. Otherwise, it is set to 1.

Pseudocode

The heart of all platform games are built around the effect of gravity, collision with platforms, and player object's ability to jump.

The pseudocode below represents the most basic platform game engine.

Check if platform below
    if no platform below turn on gravity
    else if platform, turn off gravity
    if player presses jump button, then set vspeed upward

Check if falling too fast
    if so, limit the falling speed

If collision with platform
    stop moving downward
    move player object to just before collision

If player presses right
    check no collision if moved right
    if no collision, move player object right

If player presses left
    check no collision if moved left
    if no collision, move player object left

Double Jump

A double jump is a jump in mid-air after the first jump. It also can be programmed so that the double jump can be done in mid-air after falling off a platform.

Related Pages

Backlinks

These pages link back to this page. You may find them useful.

Links

Categories: Game Physics
page_revision: 16, last_edited: 1255862535|%e %b %Y, %H:%M %Z (%O ago)