Unity Beginner Tutorial: Moving, Rotating, and Scaling Objects

Ship Controller

Estimated reading: 2 minutes 10 views Contributors

Add the New Control System

The new Input System uses Input Actions instead of the old Input.GetAxis().

Here’s how you can get your ship flying again using it:

Step 1: Create an Input Actions asset

Save the asset.

Step 1: The Setup

In your Project window → right-click → Create → Input Actions.

Name it ShipControls.

Double-click it to open the Input Actions editor.

Add a new Action Map called Flight.

Add Actions:

Move (Action Type: Value, Control Type: Vector2)

Bindings:

W/S → Up/Down

A/D → Left/Right

Look (Value, Vector2)

Binding → Mouse Delta

UpDown (Value, Axis)

Binding → Space (1)

Binding → Left Ctrl (-1)

Boost (Button)

Binding → Left Shift

Roll (Value, Axis)

Binding → Q (1)

Binding → E (-1)

  1. Open your Unity scene.
  2. Create a Cube — name it Ship.
  3. Add a Rigidbody to it (so it can move with physics).
    • Check “Use Gravity” off (we don’t want it falling).
    • Set Drag to something small like 0.1.
  4. Attach the script we’ll make next.

Step 2: The Script

Create a new C# script named ShipController.cs and paste this in:

using UnityEngine;

public class ShipController : MonoBehaviour
{
// Flight speeds
public float thrust = 20f; // Forward speed
public float strafeSpeed = 10f; // Side movement (A/D)
public float liftSpeed = 10f; // Up/down (Space/Ctrl)
public float rotationSpeed = 90f; // How fast it turns
public float rollSpeed = 90f; // Roll tilt
public float boostMultiplier = 2f; // Boost speed factor

// Rigidbody for physics-based movement
private Rigidbody rb;

void Start()
{
    rb = GetComponent<Rigidbody>();
}

void Update()
{
    // --- INPUTS ---
    float moveForward = Input.GetAxis("Vertical");   // W/S or Up/Down
    float moveRight = Input.GetAxis("Horizontal");   // A/D or Left/Right
    float moveUp = 0f;

    // Use Space/Ctrl for vertical motion
    if (Input.GetKey(KeyCode.Space)) moveUp = 1f;
    if (Input.GetKey(KeyCode.LeftControl)) moveUp = -1f;

    // Boost (Left Shift)
    bool boosting = Input.GetKey(KeyCode.LeftShift);
    float currentThrust = boosting ? thrust * boostMultiplier : thrust;

    // --- ROTATION ---
    // Mouse controls pitch and yaw
    float pitch = -Input.GetAxis("Mouse Y"); // Inverted to feel natural
    float yaw = Input.GetAxis("Mouse X");
    float roll = 0f;

    // Q/E roll the ship
    if (Input.GetKey(KeyCode.Q)) roll = 1f;
    if (Input.GetKey(KeyCode.E)) roll = -1f;

    // Apply rotation smoothly
    Vector3 rotation = new Vector3(pitch * rotationSpeed, yaw * rotationSpeed, roll * rollSpeed) * Time.deltaTime;
    transform.Rotate(rotation, Space.Self);

    // --- MOVEMENT ---
    Vector3 moveDirection = (transform.forward * moveForward * currentThrust) +
                            (transform.right * moveRight * strafeSpeed) +
                            (transform.up * moveUp * liftSpeed);

    rb.velocity = moveDirection;
}

}

Share this Doc

Ship Controller

Or copy link

CONTENTS

Chat Icon Close Icon