Menu
CoddyTech

Move Every Frame

Part of the Unity Scripting Basics section of Coddy's Unity journey. Lesson 3 of 67.

Unity calls Update() once for every frame it draws. Change the position a little in it and the object moves a little on every frame, which on screen looks like smooth motion.

+= on a position adds a Vector3 to it: each of x, y and z grows by the matching number. This balloon rises 0.02 units on every frame and stays where it is on x and z:

void Update()
{
    transform.position += new Vector3(0, 0.02f, 0);
}

The f is the C# float suffix you already know: Unity works in float, and 0.02 on its own would be a double. At 60 frames a second the balloon rises 0.02 x 60 = 1.2 units every second.

challenge icon

Challenge

Easy

Make the red car drive forward: in Update(), move it 0.05 units along the z axis on every frame. It should not move on x or y.

Press Play to watch it drive, then Check.

Try it yourself

using UnityEngine;

public class CarMover : MonoBehaviour
{
    void Update()
    {
        // Move the car forward along z here
    }
}
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Unity Scripting Basics