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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store