Using a selection of premade assets, I made a game within the Unity engine. The game consisted of a rocket having to take off from one platform and land on another all whilst avoiding rocks and meteors.

I started off with a premade level 1, scrips controlling factors such as movement and collision boxes were already correctly in place. I had to then use a 'broken' template version of this game in order to make it playable.

The assets folder is chocked full of all the spites, scenes and scripts along with other features, that I'll need to create this game.

I started out by going into the 'Sprites' section and then onto 'Ships' and selected 'playerShip' and out came my own ship sprite. I however could not use this ship yet, it had no movement controls or hitbox.
In order to make sure the ship could actually collide with other objects within the game, I had to give the ship a 'Polygon Collider 2D' component and then alter it to make it a little more clean as when first giving the spaceship a collider, it isn't very accurate. The fixing was rather easy and didn't take a lot of time.

This ship isn't too practical for a moonlander game, I gave it two stands using the glass block inside the 'Glass' section within the 'Sprites' section, I then gave the two glass boxes a 'Box Collider 2D' component and parented the two with the ship to make them apart of the same object.
Now I had to make it move, a slightly more complicated process due to assets within the scripts having public properties that I could manipulate at my leisure, in this case it would be needed. The ship needed two movement controls, one that made it move forward and one that rotated it. Thankfully the premade assets folder provided us with exactly what we needed in order to achieve this.
Within the 'Scripts' section there is a 'Movement' section containing scripts many movement patterns involving the like of buttons and following cursors. I decided to keep it simple and stick with button controls.

This is the UI for the 'Push With Button' script. It has two headings with various public areas in which I can change. Along with the implementation of this script I was automatically given a 'Rigidbody 2D' component due to the code within the script. This component makes my spaceship abide to simple laws of physics.


The Input Key heading allows me to to select what key will actually propel the spaceship forward, I kept it as 'Space' for spacebar. The Push Strength had to be upped because of the Rigidbody 2D component. After the adjustments, the spaceship moved up when I pressed the spacebar.
I now needed to make it rotate using the arrow keys, thankfully there was a script for that too.

This is the UI for the 'Rotate With Arrows' script. It consists simply of choosing what keys you want to use to rotate the player and the speed of the rotation, I stepped mine down to make control easier.

I now had a spacecraft that could move around 2D space.
Comentarios