Simple Player Movement in Unity

Rusben Guzman
2 min readMay 5, 2021

The movement is one of the most basic mechanics in every game where you have to control a player. In this example we’re gonna create a cube in Unity and add movement behaviour through a script.

  • Create a cube in your scene and name it as “Player”, Create a C# script called “Player” and attach it to the player.
  • In pseudo code this is that we have to do:
If user press movement keys     Then move the player
  • Detecting user input: for this step we’re gonna use the Input Manager, in a few words, it allows you to set up buttons and axes to associate them with actions in your project. In this case we gonna use the function Input.GetAxis() to detect when the user press the keys “A” and “S” to move sideward:
  • Improving Player movement: With this code we can move the player but too fast, we can improve the player movement adding a speed variable and the Time.deltaTime (Time.deltaTime is interval in seconds from the last frame to the current one, That means the player gonna translate 1 unit each second)
  • Finally we can get the vertical axis to move the player up and down:

--

--

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.