Kiki’s Corner
Published in

Kiki’s Corner

Jumping vs. Flying: Catching Air in MakeCode Arcade.

Jumping is harder than it looks!

Jumping is a common mechanic in video games, but when sending your character into the air, there’s more to consider than whether or not it will come back down.

Learn to Fly

In order for your sprite to take flight, it needs to have some type of upward movement. This is usually achieved by setting its vertical velocity (vy) — also known as the speed that it’s traveling in the up/down direction.

If you set the sprite’s vertical velocity to a negative number (and there’s no acceleration or friction to get in the way) your sprite will take off into the sky and never come back down!

Setting vy to negative for each push of the (A) button

Some games, like Flappy Bird, rely on a gravity mechanic that you must overcome with each push of the button. Every time you push your space bar, your bird goes higher into the air, but gravity will pull you back to the ground when you stop.

A more extreme version of this is to check to see if your character is already on the ground before allowing it to take off again. This is less like flying, and more like jumping.

Preparing for the Jump

A proper jump starts with a lift, and ends with the sprite returning to the ground. In order to make this happen, you need a negative velocity on top of a positive acceleration.

Setting a positive acceleration in your game will create a consistent “pull” toward the bottom of the screen. If you then press the (A) button to inflict negative velocity, you’ll temporarily head in an upward direction, until the acceleration overwhelms the velocity and you start dropping again.

The trick to ensuring complete jumps is to make sure that the action inside of the (A) button won’t run again until the sprite is back on the ground. You can do that with a simple if/then check.

In our Jungle Jump skillmap, we call this a gravity jump.

Getting Fancy

The code above works perfectly well for tilemap situations, but it doesn’t do a great job at handling sprite jumps in non-tilemap games.

To account for situations where only a background is used and the character may or may not travel beyond the edge of the screen, some additions were made to our special gravity jump extension.

Let’s break this down condition by condition.

  1. Is mySprite hitting a wall at the bottom?
    If so, you’re on the ground. Go for it!
  2. Is the velocity of mySprite = 0?
    If so, you’re not flying or falling. Go for it!
  3. Is the bottom of your sprite at the bottom of the screen?
    If so, you can’t have been traveling upward already. Go for it!

If any one of the above cases is true, this code will allow your character to jump again.

And now you have all the information you need to code your own jump mechanic! What kind of game will you add this to?



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kiki Prottsman

Kiki is an author, educator, and the Director of Education for Microsoft MakeCode