Simple Player Movement in Unity
Objective: Learn how to move an object with a C# script using the Transform component and its properties.
First, we need to create a script, insidethe ‘Project’ space click on the right button of the mouse, select ‘Create’ option and then ‘C# Script’, let’s call it ‘Player’ and open it.
Note: when you create your script, be sure that unity object’s name it’s the same as the class.
Now create an object on the scene, we will move the object with the script. Inside the ‘Hierarchy’ space with a click on the right button of the mouse, select the option ‘3D object’ and choose an option, I choose a cube.
Every object has their own components, our cube has a component named ‘Transform’ which has the properties of ‘Position’, ‘Rotation’ and ‘Scale’. Each one has a value in the X, Y and Z axis.
Now we need to attach the script ‘Player’ with the cube object. Just drag the script into the cube.
Let’s go to the script and move our object!!
Little note: Start function is called before the first frame update.
First, let’s call ‘transform’, then we are going to search for the position property and put the vector (0,0,0) . Now our cube will be set in the position (0,0,0) when we run the project.

For the cube running, ‘Transform’ component has a method which helps the object to move in any direction: Translate(). Using Vector3 let’s move our cube to the right (= 1,0,0 | move one positive unit on the X axis).
In the next image: on start function we are moving our cube in the position (0,0,0) that’s why it is moving up first and with the help of Update and Translate is moving to the right. BUT as we can see it’s too fast, the reason is that Update is called once per frame (= 60 aprox. frames per second ) and our vector 3 is moving one unit per second and a unit is equivalent to one meter (= 60 meter per second ) SO we need to slow down a bit and the right movement will be 1 meter per second.
With the help of deltaTime we can move in seconds, multiplying the value by deltaTime we get to move in real time.