Simple Player Movement in Unity

Set up the scene

In order to implement player movement we are going to need something in our scene to act as our player. Add a cube to the scene and name it Player. The scene should look similar to

Time to start coding

Move the player

To get the player to move we will need to use a method on the transform called Translate. Lets move the Player to the left at real time.

Add a speed variable

Lets add a speed variable that is only access from the player script but lets make sure that our game designers can change the speed in the inspector.

User Input

Now lets use Unity’s Input System to control the player movement.

Keeping the player in Bounds

Lets add some code to keep the player within a bounds set by the designer on the screen.

Code Clean up

Add a variable to keep track of the direction to move the player.

The Completed Class

Excited about changing my hobby into a new carer with GameDevHQ course.