---
title: "Lesson 1.2 - Pedal to the Metal"
content_type: tutorial
url: "https://learn.unity.com/tutorial/1-2-move-the-vehicle-with-your-first-line-of-c?language=en"
language: en
difficulty: beginner
duration_minutes: 70
unity_version:
  - "6.0"
  - "6.3"
supported_unity_versions:
  - name: "6.0"
    url: "https://learn.unity.com/tutorial/1-2-move-the-vehicle-with-your-first-line-of-c.md?language=en&version=6.0"
  - name: "6.3"
    url: "https://learn.unity.com/tutorial/1-2-move-the-vehicle-with-your-first-line-of-c.md?language=en&version=6.3"
  - name: "2022.3"
    url: "https://learn.unity.com/tutorial/1-2-move-the-vehicle-with-your-first-line-of-c.md?language=en&version=2022.3"
  - name: "2021.3"
    url: "https://learn.unity.com/tutorial/1-2-move-the-vehicle-with-your-first-line-of-c.md?language=en&version=2021.3"
available_languages:
  - name: "en"
    url: "https://learn.unity.com/tutorial/1-2-move-the-vehicle-with-your-first-line-of-c.md?language=en"
  - name: "ja"
    url: "https://learn.unity.com/tutorial/1-2-move-the-vehicle-with-your-first-line-of-c-1-jp.md?language=ja"
  - name: "ko"
    url: "https://learn.unity.com/tutorial/1-2gang-caryange-dongryeog-mandeulgi.md?language=ko"
last_updated: "2026-08-18T17:18:44.000Z"
---

# Lesson 1.2 - Pedal to the Metal

Learn to script basic vehicle movement, add physics components for collisions, and duplicate road objects in the Hierarchy window.

**Overview:**

In this lesson you will make your driving simulator come alive. First you will write your very first lines of code in C#, changing the vehicle’s position and allowing it to move forward. Next you will add physics components to your objects, allowing them to collide with one another. Lastly, you will learn how to duplicate objects in the hierarchy and position them along the road.

**Project Outcome:**

You will have a moving vehicle with its own C# script and a road full of objects, all of which may collide with each other using physics components.

Overview: [Video](https://connect-mediagw.unity.com/h1/20241203/videos/4c7dbef2-39a8-430a-89d0-906696736f79_CWC_U1.L2.S0_Intro_U6.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20241203/3ffe5565-bd98-4c45-91c3-d378b6cd7505_CWC_U1.L2.S0_Intro_U6.mp4.vtt))

## 1. Create and apply your first script

We will start this lesson by creating our very first C# script that will control the vehicle’s movement.

[Video](https://connect-mediagw.unity.com/h1/20241203/videos/18a5c638-8e8d-4c33-b8fd-245f3e001928_CWC_U1.L2.S1_U6_1.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/420510c0-dd9f-47f0-996e-9d012b15b45e/versions%5B_key==%22VjARa8C3EIBGSbYTjQCruz%22%5D.sections%5B_key==%228KfwgJtj1rZ1EivCZvbRjQ%22%5D.body%5B_key==%228KfwgJtj1rZ1EivCZvbRsO%22%5D.subtitles/CWC_U1.L2.S1_U6.mp4_20260504_172028.srt))

1. In the Project window, _Right-click >_ _Create **> Folder**_ named “Scripts”
2. In the “Scripts” folder, _Right-click  > Create >_ **_Monobehaviour Script_** named “PlayerController”
3. **Drag** the new script onto the **Vehicle object**
4. **Click** on the Vehicle object to make sure it was added as a **Component** in the Inspector

## 2. Add a comment in the Update() method

In order to make the vehicle move forward, we have to first open our new script and get familiar with the development environment.

[Video](https://connect-mediagw.unity.com/h1/20241203/videos/725e091f-1249-4f1b-81b8-c19b6bb638f3_CWC_U1.L2.S2_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/420510c0-dd9f-47f0-996e-9d012b15b45e/versions%5B_key==%22VjARa8C3EIBGSbYTjQCruz%22%5D.sections%5B_key==%228KfwgJtj1rZ1EivCZvbTgU%22%5D.body%5B_key==%228KfwgJtj1rZ1EivCZvbTpS%22%5D.subtitles/CWC_U1.L2.S2_U6.mp4_20260504_163048.srt))

1. **Double-click** on the script to open it in **Visual Studio**
2. In the **_Update()_** method, add a comment that you will:  **_// Move the vehicle forward_**

![](https://connect-mediagw.unity.com/h1/20190529/learn/images/3c0cc59d-fc73-40af-abf3-497a2d135196_1.2_2.PNG)

## 3. Give the vehicle a forward motion

Now that we have the comment saying what we WILL program - we have to write a line of code that will actually move the vehicle forward.

[Video](https://connect-mediagw.unity.com/h1/20241203/videos/889c32d3-1fee-4c51-9a11-d71967049751_CWC_U1.L2.S3_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/420510c0-dd9f-47f0-996e-9d012b15b45e/versions%5B_key==%22VjARa8C3EIBGSbYTjQCruz%22%5D.sections%5B_key==%228KfwgJtj1rZ1EivCZvbUYI%22%5D.body%5B_key==%228KfwgJtj1rZ1EivCZvbUhG%22%5D.subtitles/CWC_U1.L2.S3_U6.mp4_20260504_163140.srt))

1. Under your new comment, type **_transform.tr_**, then select **Translate** from the autocomplete menu.
2. Type **()**, add **0, 0, 1** between the parentheses, and complete the line with a semicolon (**;**).
3. Press **Ctrl/Cmd + S** to save your script, then run your game to test it.

![](https://connect-mediagw.unity.com/h1/20190522/learn/images/33e3d9bb-9b78-4634-a373-09a496ce707b_1_2_3.png)

**Note:** For the autocomplete to work correctly, your IDE must have the correspondent Unity plugin installed

## 4. Use a Vector3 to move forward

We’ve programmed the vehicle to move along the Z axis, but there’s actually a cleaner way to code this.

[Video](https://connect-mediagw.unity.com/h1/20241203/videos/b1f5be6d-eb92-40ff-854e-de42cc022903_CWC_U1.L2.S4_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/420510c0-dd9f-47f0-996e-9d012b15b45e/versions%5B_key==%22VjARa8C3EIBGSbYTjQCruz%22%5D.sections%5B_key==%228KfwgJtj1rZ1EivCZvbW8w%22%5D.body%5B_key==%228KfwgJtj1rZ1EivCZvbWHu%22%5D.subtitles/CWC_U1.L2.S4_U6.mp4_20260504_163207.srt))

1. **Delete** the 0, 0, 1 you typed and use auto-complete to **replace it** with **_Vector3.forward_**

![](https://connect-mediagw.unity.com/h1/20190522/learn/images/eabc376a-d169-4484-9a83-40aa34ee0adc_1_2_4.png)

## 5. Customize the vehicle’s speed

_Right now, the speed of the vehicle is out of control! We need to change the code in order to adjust this._

[Video](https://connect-mediagw.unity.com/h1/20241203/videos/9a4858e7-abc7-4373-b1f8-c4f81eedc0f9_CWC_U1.L2.S5_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/420510c0-dd9f-47f0-996e-9d012b15b45e/versions%5B_key==%22VjARa8C3EIBGSbYTjQCruz%22%5D.sections%5B_key==%228KfwgJtj1rZ1EivCZvbWwG%22%5D.body%5B_key==%228KfwgJtj1rZ1EivCZvbX5E%22%5D.subtitles/CWC_U1.L2.S5_U6.mp4_20260504_163240.srt))

1. Add **_\* Time.deltaTime_** and run your game
2. Add **_\* 20_** and run your game

![](https://connect-mediagw.unity.com/h1/20190522/learn/images/8af0526d-9f43-41de-8119-ad4552242556_1_2_5.png)

## 6. Add RigidBody components to objects

Right now, the vehicle goes right through the box! If we want it to be more realistic, we need to add physics.

[Video](https://connect-mediagw.unity.com/h1/20241203/videos/687b9cff-9869-4d04-87bf-8d59d8cc4d00_CWC_U1.L2.S6_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/420510c0-dd9f-47f0-996e-9d012b15b45e/versions%5B_key==%22VjARa8C3EIBGSbYTjQCruz%22%5D.sections%5B_key==%228KfwgJtj1rZ1EivCZvbXja%22%5D.body%5B_key==%228KfwgJtj1rZ1EivCZvbXsY%22%5D.subtitles/CWC_U1.L2.S6_U6.mp4_20260504_163304.srt))

1. Select the **Vehicle**, then in the inspector click **Add Component** and select **RigidBody**
2. Select the **Obstacle**, then in the inspector click **Add Component** and select **RigidBody**
3. In the RigidBody component properties, increase the **mass** of the vehicle and obstacle to be about what they would be in **kilograms** and test again

## 7. Duplicate and position the obstacles

Last but not least, we should duplicate the obstacle and make the road more treacherous for the vehicle.

[Video](https://connect-mediagw.unity.com/h1/20241203/videos/32f79c41-ff99-4e1a-947f-4fb6be9d1b8f_CWC_U1.L2.S7_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/420510c0-dd9f-47f0-996e-9d012b15b45e/versions%5B_key==%22VjARa8C3EIBGSbYTjQCruz%22%5D.sections%5B_key==%228KfwgJtj1rZ1EivCZvbZFk%22%5D.body%5B_key==%228KfwgJtj1rZ1EivCZvbZOi%22%5D.subtitles/CWC_U1.L2.S7_U6.mp4_20260504_163330.srt))

1. Click and drag your obstacle to the **bottom of the list** in the hierarchy
2. Press **Ctrl/Cmd+D** to duplicate the obstacle and move it down the **Z axis**
3. Repeat this a few more times to create more obstacles
4. After making a few duplicates, select one in the hierarchy and **hold ctrl** **+ click** to select multiple obstacles, then **duplicate** those

## 8. Lesson Recap

## New Functionality

- Vehicle moves down the road at a constant speed
- When the vehicle collides with obstacles, they fly into the air

## New Concepts & Skills

- C# Scripts
- Start vs Update
- Comments
- Methods
- Pass parameters
- Time.deltaTime
- Multiply (\*) operator
- Components
- Collider and RigidBody

## Next Lesson

- We’ll add some code to our camera, so that it follows the player as they drive along the road.

## Check your script

```csharp
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    void Start()
    {
        
    }

    void Update()
    {
        // Move the vehicle forward
        transform.Translate(Vector3.forward * Time.deltaTime * 20);
    }
}
```
