6 Creating a basic 2D platformer

 

This chapter covers

  • Moving sprites around continuously
  • Playing sprite-sheet animation
  • Working with 2D physics (collision, gravity)
  • Implementing camera control for side-scrolling games

Let’s create a new game and continue learning about Unity’s 2D functionality. Chapter 5 covered the fundamental concepts, so this chapter builds on those to create a more elaborate game. Specifically, you are going to build the core functionality of a 2D platform game. Also called a platformer, this common type of 2D action game is best known for classics like Super Mario Brothers: a character viewed from the side runs and jumps on platforms, and the view scrolls around to follow. Figure 6.1 shows what the end result will be.

Figure 6.1 The final product of this chapter
CH06_F01_Hocking3

This project will teach concepts like moving the player left and right, playing the sprite’s animation, and adding the ability to jump. We’ll also go over several special features common in platform games, like one-way floors and moving platforms. Going from this shell to a full game mostly means repeating those concepts over and over.

6.1 Setting up the graphics

 
 

6.1.1 Placing the scenery

 
 

6.1.2 Importing sprite sheets

 
 
 
 

6.2 Moving the player left and right

 
 
 

6.2.1 Writing keyboard controls

 
 

6.2.2 Colliding with the block

 
 
 

6.3 Playing the sprite’s animation

 

6.3.1 Explaining the Mecanim animation system

 
 

6.3.2 Triggering animations from code

 
 

6.4 Adding the ability to jump

 
 
 
 

6.4.1 Falling from gravity

 
 

6.4.2 Applying an upward impulse

 
 
 

6.4.3 Detecting the ground

 
 

6.5 Additional features for a platform game

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest