---
title: "Lesson 2.1 - Player Positioning"
content_type: tutorial
url: "https://learn.unity.com/course/unit-2-basic-gameplay/tutorial/lesson-2-1-player-positioning?language=en"
language: en
container_type: course
container_title: "Unit 2 - Basic Gameplay"
container_url: "https://learn.unity.com/course/unit-2-basic-gameplay.md?language=en&version=6.0"
standalone_markdown_url: "https://learn.unity.com/tutorial/lesson-2-1-player-positioning.md?language=en&version=6.0"
previous_title: "Unit 2 - Introduction"
previous_url: "https://learn.unity.com/course/unit-2-basic-gameplay/tutorial/unit-2-introduction?language=en&version=6.0"
previous_markdown_url: "https://learn.unity.com/course/unit-2-basic-gameplay/tutorial/unit-2-introduction.md?language=en&version=6.0"
next_title: "Lesson 2.2 - Food Flight"
next_url: "https://learn.unity.com/course/unit-2-basic-gameplay/tutorial/lesson-2-2-food-flight?language=en&version=6.0"
next_markdown_url: "https://learn.unity.com/course/unit-2-basic-gameplay/tutorial/lesson-2-2-food-flight.md?language=en&version=6.0"
difficulty: beginner
duration_minutes: 60
unity_version:
  - "6.0"
  - "6.3"
supported_unity_versions:
  - name: "6.0"
    url: "https://learn.unity.com/course/unit-2-basic-gameplay/tutorial/lesson-2-1-player-positioning.md?language=en&version=6.0"
  - name: "6.3"
    url: "https://learn.unity.com/tutorial/lesson-2-1-player-positioning.md?language=en&version=6.3"
  - name: "2022.3"
    url: "https://learn.unity.com/course/unit-2-basic-gameplay/tutorial/lesson-2-1-player-positioning.md?language=en&version=2022.3"
  - name: "2021.3"
    url: "https://learn.unity.com/course/unit-2-basic-gameplay/tutorial/lesson-2-1-player-positioning.md?language=en&version=2021.3"
last_updated: "2026-08-04T14:24:03.000Z"
---

# Lesson 2.1 - Player Positioning

Create a new prototype project and script side-to-side player movement that stays within the play area using if-then logic.

**Overview:**

You will begin this unit by creating a new project for your second Prototype and getting basic player movement working. You will first choose which character you would like, which types of animals you would like to interact with, and which food you would like to feed those animals. You will give the player basic side-to-side movement just like you did in Prototype 1, but then you will use if-then statements to keep the Player in bounds.

**Project Outcome:**

The player will be able to move left and right on the screen based on the user’s left and right key presses, but will not be able to leave the play area on either side.

Overview: [Video](https://connect-mediagw.unity.com/h1/20241208/videos/92c6801b-8c61-4d9f-8dad-1b021c7b7d2e_CWC_U2.L1_Intro_U6.mp4) ([Transcript (en)](https://connect-mediagw.unity.com/h1/20241208/44487879-6511-48ae-b8dd-d7b77ce55130_CWC_U2.L1_Intro_U6.mp4.vtt))

## Materials

- [Prototype 2 - Starter Files](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.materials%5B_key==%22467d5b84b551%22%5D.file/Prototype-2_Starter-Files_U6_20260613_025845.unitypackage)

## 1. Create a new Project for Prototype 2

The first thing we need to do is create a new project and import the Prototype 2 starter files.

[Video](https://connect-mediagw.unity.com/h1/20241205/videos/cf761123-b649-40bd-813c-ed734d4346eb_CWC_U2.L1.S1_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOflWo%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOflb6%22%5D.subtitles/CWC_U2.L1.S1_20260505_042236.srt))

1. Open **Unity Hub** and create an empty “Prototype 2” project in your course directory on the correct Unity version.
   If you forget how to do this, refer to the instructions in [Lesson 1.1 - Step 1](https://learn.unity.com/course/create-with-code/unit/unit-1-driving-simulation/tutorial/lesson-1-1-start-your-3d-engines?version=6.0#674f41a1edbc2a1e806fc55b).
2. Click to download the [Prototype 2 Starter Files](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.materials%5B_key==%22467d5b84b551%22%5D.file/Prototype-2_Starter-Files_U6_20260613_025845.unitypackage), **extract** the compressed folder, and then **import** the .unitypackage into your project.
   For instructions on importing packages, refer to the [Import local asset packages](https://docs.unity3d.com/Manual/AssetPackagesImport.html) documentation.

   **Note:** If you see warnings in the Console after importing the package into your project, you can safely ignore them. Open the Console and click the **Clear** button.

3. From the Project window, open the **Prototype 2** scene and **delete** the SampleScene.
4. In the top-right of the Unity Editor, change your **Layout** from Default to your custom layout.

![](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOflWo%22%5D.body%5B_key==%226cb221765e10%22%5D.image/unnamed_20260603_000843.png)

## 2. Add the Player, Animals, and Food

Let’s get all of our objects positioned in the scene, including the player, animals, and food.

[Video](https://connect-mediagw.unity.com/h1/20241208/videos/df70b401-55c5-4e56-8622-7d209effffb4_CWC_U2.L1.S2_U6.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfmQa%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfmUs%22%5D.subtitles/CWC_U2.L1.S2_U6.mp4_20260505_034751.srt))

1. If you want, drag a different **material** from _Course Library > Materials_ onto the Ground object
2. Drag 1 **Human**, 3 **Animals**, and 1 **Food** object into the Hierarchy.
3. Rename the character “Player”, then **reposition** the animals and food so you can see them.
4. Adjust the XYZ **scale** of the food so you can easily see it from above.

![](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfmQa%22%5D.body%5B_key==%22b0a17956e911%22%5D.image/unnamed%20%281%29_20260603_000944.png)

## 3. Configure project settings for the Input System

The code you’ll add in the following steps uses the **Input System** to handle player controls. To ensure the code works correctly, verify that your project is configured to allow both input systems to run side by side.

Follow the video and instructions below.

[Video](https://connect-mediagw.unity.com/h1/20250903/videos/89a8fcf6-41e6-4a5c-aae5-49a3825881cf_ChangeInputSystem.mp4)

## Instructions

**1.** Open the **Player Settings**:

- From the main menu, select **Edit** > **Project Settings,** then select the **Player** category from the leftmost panel.

**2.** Enable support for both input systems:

- Find the **Configuration** section.
- From the **Active Input Handling** dropdown, select **Both**.
- Select the **Apply** button to confirm the change.

The Unity Editor will automatically restart to apply this setting. After restarting, your project will be correctly configured to handle input from both the original Input Manager and the newer Input System.

## 4. Configure a new moveAction variable

Now let’s add a **Move** **Action** using Unity’s newer Input System and bind the Left/Right arrow keys in the **Inspector** window.

[Video](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfnG4%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfnKM%22%5D.overviewVideo/Unit%202.1%20-%20Step%204%20-%20Configure%20a%20new%20moveAction%20variable%20-%20FINAL%20NEW_20260625_200719.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfnG4%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfnKM%22%5D.subtitles/Unit%202.1%20-%20Step%204%20-%20Configure%20a%20new%20moveAction%20variable%20-%20FINAL%20NEW_20260625_200956.vtt))

1. In your **Assets** folder, create a “Scripts” folder and a “PlayerController” script.
2. Attach the script to the **Player** GameObject and open it.
3. Add **public InputAction moveAction;** at the top of the class.
4. Save and return to Unity. If you see an error about **InputAction** not found, add the following **using** statement:
   - **using UnityEngine.InputSystem;**
   - If your Editor suggests it, accept the auto-complete/quick fix.
5. In the **Inspector** window, select the **Player** GameObject, expand the **Move Action** section, and set up bindings for Left/Right arrows:
   - Select **+** **Add** **Binding**, then select **Add Up/Down/Left/Right Composite**.
   - Set Left = keyboard/leftArrow and Right = keyboard/rightArrow.
   - You can also add Up/Down later for forward/back if needed.

![](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfnG4%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfnz7%22%5D.image/Untitled_20260603_001913.png)

## 5. Get Vector2 values for Input

Now let’s read your **Move** **Action** as a **Vector2** so you can see left/right input values in Play Mode.

[Video](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfo1G%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfo5Y%22%5D.overviewVideo/Unit%202.1%20-%20Step%205%20-%20Get%20Vector2%20values%20for%20input%20-%20FINAL%20NEW_20260625_201018.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfo1G%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfo5Y%22%5D.subtitles/Unit%202.1%20-%20Step%205%20-%20Get%20Vector2%20values%20for%20input%20-%20FINAL%20NEW_20260625_201156.vtt))

1. Update your script to add **public** **Vector2 moveInput;**
2. At the **Start** method, call **moveAction.Enable();** to activate the input.
3. In the **Update** method, read the input by calling **moveInput = moveAction.ReadValue\<Vector2>();** to update the movement vector each frame.
4. Enter Play mode, select your Player in the **Hierarchy** window, and watch **moveInput** in the **Inspector** window.
   - Press Left Arrow: moveInput.x should be -1.
   - Press Right Arrow: moveInput.x should be +1.
   - If you didn’t bind Up/Down yet, **moveInput.y** will remain 0.

![](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfo1G%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfoT9%22%5D.image/Untitled_20260603_002243.png)

## 6. Make the player move based on input

Now let’s use your horizontal input to move the **Player** GameObject and add a speed control.

[Video](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22f0918954c485%22%5D.body%5B_key==%228106e8ad3894%22%5D.overviewVideo/Unit%202.1%20-%20Step%206%20-%20Make%20the%20player%20move%20based%20on%20input%20-%20FINAL%20NEW_20260625_201217.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22f0918954c485%22%5D.body%5B_key==%228106e8ad3894%22%5D.subtitles/Unit%202.1%20-%20Step%206%20-%20Make%20the%20player%20move%20based%20on%20input%20-%20FINAL%20NEW_20260625_201309.vtt))

1. Declare a public speed variable by adding **public float speed = 10.0f;** so you can adjust movement speed in the **Inspector** window.
2. In the **Update** method, move the GameObject horizontally by calling **transform.Translate(Vector3.right \* moveInput.x \* Time.deltaTime \* speed);**
3. Enter Play mode and test:
   - Left Arrow moves left, Right Arrow moves right.
   - Adjust “speed” in the Inspector to change movement pace.

![](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22f0918954c485%22%5D.body%5B_key==%22eb71b65262ee%22%5D.image/Untitled_20260603_005840.png)

## 7. Keep the player inbounds

We have to prevent the player from going off the side of the screen with an if-then statement.

[Video](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfoVI%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfoZa%22%5D.overviewVideo/Unit%202.1%20-%20Step%207%20-%20Keey%20the%20player%20inbounds%20-%20FINAL%20NEW_20260625_201329.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfoVI%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfoZa%22%5D.subtitles/Unit%202.1%20-%20Step%207%20-%20Keey%20the%20player%20inbounds%20-%20FINAL%20NEW_20260625_201517.vtt))

1. In **_Update()_**, write an **if-statement** checking if the player’s left X position is **less than** a certain value
2. In the if-statement, set the player’s  position to its current position, but with a **fixed X location**

![](https://connect-mediagw.unity.com/h1/20190621/learn/images/99fa70e7-48b6-4877-85c5-161d0261f2b5_Screen_Shot_2019_06_21_at_11.57.13_AM.png)

## 8. Clean up your code and variables

We need to make this work on the right side, too, then clean up our code.

[Video](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfozK%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfp3c%22%5D.overviewVideo/Unit%202.1%20-%20Step%208%20-%20Clean%20up%20your%20code%20and%20variables%20-%20FINAL%20NEW_20260625_201542.mp4) ([Transcript (en)](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfozK%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfp3c%22%5D.subtitles/Unit%202.1%20-%20Step%208%20-%20Clean%20up%20your%20code%20and%20variables%20-%20FINAL%20NEW_20260625_201701.vtt))

1. Repeat this process for the **right side** of the screen
2. Declare new **_xRange_** variable, then replace the hardcoded values with them
3. Add **comments** to your code

![](https://storage.googleapis.com/learn-platform-bucket-production/tutorial/c16d7a63-0db1-4f1c-81b5-072968e726d8/versions%5B_key==%22557b55aacd55%22%5D.sections%5B_key==%22u6X2hMV4GZ96GPitLOfozK%22%5D.body%5B_key==%22u6X2hMV4GZ96GPitLOfpRD%22%5D.image/Untitled_20260603_010009.png)

## 9. Lesson Recap

##  New Functionality

- The player can move left and right based on the user’s left and right key presses
- The player will not be able to leave the play area on either side

## New Concepts & Skills

- Adjust object scale
- If-statements
- Greater/Less than operators

## Next Lesson

- We’ll learn how to create and throw endless amounts of food to feed our animals!

## Review your script

PlayerController.cs

```csharp
using UnityEngine;
using UnityEngine.InputSystem;

public class PlayerController : MonoBehaviour
{
    public InputAction moveAction;
    public Vector2 moveInput;
    public float speed = 10.0f;
    public float xRange = 10.0f;

    void Start()
    {
        moveAction.Enable();
    }

    void Update()
    {
        // Keep the player in bounds
        if (transform.position.x < -xRange)
        {
            transform.position = new Vector3(-xRange, transform.position.y, transform.position.z);
        }
        if (transform.position.x > xRange)
        {
            transform.position = new Vector3(xRange, transform.position.y, transform.position.z);
        }

        moveInput = moveAction.ReadValue<Vector2>();
        transform.Translate(Vector3.right * moveInput.x * Time.deltaTime * speed);
    }
}
```
