For our last game prototype tutorial, I was tasked to create and code a ball to shoot missiles and be moveable with arrow keys. Beforehand, I had only known how to code "point and click" mini-games but now I was able to use my skills from previous lessons to make a similar effort here. As you'll see the level created at the end has a similar look to my AI agents arena prototype level but now that the character has some offense to use.
At first I created a sphere and a blank green floor object into the scene, then like usual created a script and called it "SphereMovement". Before writing the script however, I looked into the system settings in unity and looked at the movement controls. Here I could set specific keyboard controls to the objects mobility, the spacebar button would be assigned as our second main ability. I did not code the character to jump, instead this would be exchanged for a shoot (& destroy) ability. 

changing and viewing controls for movement

Movement script. horizontal controls

While writing the code, I took a video to show my halfway progress, as you can see below, the camera is positioned at level eye view and the sphere can move in a full 360' degree circle. This would then allow me to create structures around it and walls to bypass, possibly more AI agents to escape from. The code I wrote in visual studios above has some new terminology that helped me reach this point. Having written "Horizontal" for speed and axis meant that the sphere could move on the horizontal plane. If I wrote vertical, this would allow the sphere to move upwards and downwards. I could also change the speed of the sphere and its mass to amke it heavier if I wanted to.

Video showcasing the sphere I had coded to move in each direction and spin in a 360 circle.

making a missile 

Shooting code

The next step in this prototype was to give our character some offence, this would be in the form of missiles and eject themselves from the centre of the player. First I put the capsule object into the scene and then wrote some code as you can see above that would make the "Missile" have a rigidbody to allow it to hit any other object nearby. But to make sure I couldn't spam this attack, I wrote in the code to delete the missiles after a certain range and amount. This even with a buffer still led to some havoc later on down the line. I also set the speed to 10 so they could be shot quite quickly when played.

updated missile and movement on Unity

updated movement script

ball shooting missile

updated coloured level layout

After creating the missile and finishing the text, I updated the prototype level area by adding higher walls and coloured defences in different sizes. There is also a gap in the middle to shoot the missiles through. To continue this prototype I would add targets beyond this slit window and the player would be able to shoot them with the missiles, perhaps with a time limit to gain them a collectable of sorts. 
The player also as a prefab no longer falls through the floor when firing the missiles, this was a bug that was later fixed and meant that no longer the missiles would start shoot from underneath the players spawn.
And lastly the code was also updated on the movement script; the player would press the space key to shoot the missiles & these could be shot horizontally or vertically. There was also speed and transformations on each.

This video showcases myself using the missile shooting mechanics on my newly design level.

The video above showcases my most recent iteration of the prototype level I had created, The player is able to move freely with some restrictions for the camera and is able to shoot missiles at whatever targets I may place later on. The level design is simple, much like last weeks but incorporates a camo green selection which would make the player feel like they are actually in a battlefield. 
I did like usual have some setbacks with the coding this being the player having the ability to jump. I did not expect this, nor did I know it could happen as you can see from this quote from earlier in this blog. ---> "I did not code the character to jump"
For some reason as you can see in the video above, when the player shoots the missiles, they have recoil making themselves be propelled backwards in any direction. It even made he character fall under the map, as cool as my local classmates thought this was, I asked Harry (my nearest classmate) for help. With the lesson ending I decided to leave it as it was. A lot of games recently have had bugs that the players enjoy and benefit their experience, this could also be a "bonus feature"
I did not see if anyone else in class had encountered this but to me and my friends it was a cool and unexpected game mechanic.

Updated level layout

Back to Top