The Empty Unity Scene
Starting a new journey with a blank unity scene. There’s something exciting and at the same time daunting about it.
There’s so many directions you can take, seemingly limitless.
I thought about writing about the various windows/views/panels, my layout is already set up the way I like it. Instead I chose to get started on the project itself.
I’ll be documenting my development efforts here on medium.
Placing my cube and getting it moving is the first step towards making this a “Space Shooter”
Getting the input from the named axes in the input manager and setting them to variables. One for the horizontal and another for the vertical axis.
That way I don’t have to map each key in script and it’s more versatile, it should support a gamepad by default 😁
The input is then set to a Vector3 I decide to call “movement”.
A vector3 is a type you can use in unity that stores 3 values, each representing a direction/axis: Vector3(x (red), y (green), z(blue))
Since this will be a game only taking place in 2D, I will be using the X and Y axes: X for moving left and right, Y for moving up and down. Z is for moving forwards and backwards, which I would need if this was 3D instead.
var hInput = Input.GetAxis("Horizontal");
var vInput = Input.GetAxis("Vertical");
Vector3 movement = new Vector3(hInput, vInput) * Time.deltaTime * _speed;
transform.Translate(movement);
I could use transform.position += movement
, but at this stage that doesn’t matter. Translate takes the objects rotation into account, setting the position just moves it in what’s known as world space :)
Thank you for you time and attention, have a great one!