Beginner: 2D Platformer Game Development

I have been meaning to get to this post for quite some time, and I have been working on this project for a while now. I plan on updating this every week to report on my progress.

I am working on a 2D platformer by following inScope Studio‘s Unity 5 Tutorial. It’s been a lot of fun, and so far I have learned how to script the enemy’s idle animation, running animation, attack animation, slide animation, player movement, flipping the player (when it changes directions), and I began creating a level. Up next, I am learning how to code the player’s jump animation. The game assets are licensed under Creative Common Zero (CC0) a.k.a Public Domain license and can be found at Game Art 2D.

Learning C# through building a game has been great. I have a better understanding of object oriented programming since I began my journey on learning how to develop video games.

I have a tendency to take a lot of notes when I’m learning something new. I made sure to comment every line of code while I’m learning in a detailed way that explains what is going on in the game.

There’s no possible way that I can tell you everything that I have been working on, but let’s take a look at what I think is kind of cool…

The Player Game Object & Player Controller

The player controller script is where I guess I’ll start, since this is what I have been working on for quite some time. Up until this week, the player controller script has been responsible for handling all player movement and animation.  This means that when I hit a key on the keyboard, my player will do what I want it to. Most of the code that I have been working on has been thrown out because I have now given a lot more functionality to the animations instead. This was because I wanted to give my player the ability to throw knives, and to do so I would have to generate a knife sprite that will travel in the direction the player is facing whenever the player does a throw animation.

In terms of how the script affects the player Rigidbody, the player controller determines the character movement speed, the player movement such as the jump force (how high the player can jump) and air control (This checks if the player is in the air and prevents the player from being able to “run” in the air. It is less “natural” but resembles the jump functionality in other games more closely). The player also has ground points that are 2D colliders to ensure that the player is grounded. The script checks if the player is not falling (so the player’s y velocity is 0, then checks if the ground point colliders on the player are colliding with the ground colliders).

Player Animator

The player has two layers. When the player is on the ground, the ground layer is activated and when the player is in the air the air layer is activated. Sounds simple right?

The ground layer has two states: Idle States and Action States. When the player is on the ground and isn’t moving, the player cycles through two Idle States: Idle and Sleeping.

When the player is moving, the animator switches between several animations: Run, Slide Attack, Throw.

When the player is not on the ground (in the air) the animator layers change. The player can jump (takeoff), jump throw, jump attack, and of course land.

When the player is in a certain stage of the throw animation, a knife sprite is generated that travels in the direction the player is facing.

Conclusion

Well, I’m going to leave it there for now. I have done a lot more work outside of that, such as level design, but I will leave that for when the game is a little more polished. I am working on creating enemies this week for the game.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s