Tuesday, March 31, 2015

Jumping and Double Jumping in a Unity 2D Platform Game (with JavaScript and C#)

Jumping and Double Jumping in a Unity 2D Platform Game (with JavaScript and C#)

This is part 2 of a series of tutorials for Buiding a 2D Platform Game in Unity.

An essential part of a platform game is the ability to jump. Sometimes you need to jump over barrels, onto mushroom people, or just jump up to the next platform.


Space Panic, released in November 1980, is probably the first platform game, but Donkey Kong introduced the jump mechanic in 1981.
This tutorial is presented in two videos: one video each for JavaScript and C# (C-Sharp). I've presented both languages, since it's sometimes not clear how to convert code from the other language when watching a tutorial. The code performs the same functions and produces the same game play, so you only need to watch one.

In this video we...
  • use the JavaScript or C-Sharp (C#) language
  • add a script component to our actor
  • add jumping with space bar key
  • tag objects as "Ground"
  • use GetKeyDown
  • use GetComponent(RigidBody2D)
  • use Vector2
  • use OnCollisionEnter2D
  • add double jumping 
  • refactor code into a function 

JavaScript (Unity Script) version


C# (C-Sharp) version




This tutorial builds on the first project and the GitHub tag for this tutorial is v2


In the next video, I will be showing how to add left/right movement.

Be sure to subscribe to the Playlist to get the future updates: Unity 5 2D Platform Game Development (Mac) Playlist

1 comment:

  1. If my character attribute gravity scale = 5, it will be down, not standing on the ground?

    please contact: khoanad@gmail.com
    Thank and Best Ragard.

    ReplyDelete