The basic movement in unity

When creating a 2D avatar based game on Unity, implementing the movement of the player is the first step. The moving style of player avatar is also an important mechanic. There are several kinds of pattern we tried for the game we are making.

9

The game concept we selected is Aestherial which you are controlling a pirate ship and fighting sky creatures. When came to the discussion of player movement, we were trying to simulate a feeling that you are flying at sky. Therefore the movement shouldn’t be really smooth that there is a slight delay before you reach the max speed.

So, the movement in game is basically changing the position of the game object every frame. For most of the 2D games, they run 60 frames per second. If you want to move the play with a speed of 120 pixels per second, then the speed should be 2 pixels per frame. However, the speed should be controlled by keyboard input. For example, as you holding the left key the speed is 2 in X axis, if you holding right key then the speed should be -2, if you holding both or none of them it’s 0, the same in Y axis.

The way to create a floaty move pattern is not to decline the speed of the player when you released the input button and not to increase the speed the moment you pressed button. Unity provides a function for receiving input and gives you a value vary from -1 to 1. So we multiply the value with the speed we should give the player, in the previous case, the speed is 2 pixel per second. And now, when I press Left bottom, the speed of player increases constantly from 0 to 2, or when i release it, then speed also drops down from 2 to 0 continuously.

10

This pattern used widely when the game requires a acceleration for player avatar. Mario Brother series are all good instances, Nintendo uses floaty movement for almost all versions of Mario. Though for pure RPG games like Final Fantasy 1-6 an instant movement also works well, it’s still something we need to think about because nobody want their walks like teleportation unless they intended to.

About Hangning Zhang

2017 Programming