2D Spaceship Thrust Control in Unity Part One

The “Player” game object

Objective: Add movement to our spaceship or what we will refer to as our “Player” game object.

By accessing the “Transform” of our “Player” (The Spaceship game object) we can move it around using the “transform.Translate” function call.

In the code above we use Unity’s built-in Input Manager.

We then assign the value returned from the “Input.GetAxis(“Horizontal”)” function call to the private float variable “_horizontalInput” and we follow the same method for the vertical movement.

With just 4 lines of C#, we have an operational spaceship.

In part two we will add thrusters to add more realism to our spaceship.

--

--