Friday 8 April 2016

2D Group Game Coding

I was in charge of the main bulk of coding and putting the game together. I also did the designs for the boss. This was a long process as my initial designs did not work out and proved too hard to code in the time we had.  

I found making a 2D game in Unity interesting. I have made 2D games before so I have had some experience. However, I did meet several challenges. Such as having to figure out how to do things in C# that I have done in other languages. 
The most challenging bit of code for me to create was the boss code. I initially made one script for 2 Boss Parts. The idea came from a hive mind concept that I came up with and I was just experimenting with code in Unity. I took a video of the initial prototype for the boss. It was pretty static and wouldn't have worked for the final boss fight. Also the small drones flew up if they were next to each other. This turned out to be because of a collision check recognising the drones as the ground. 
I made the AI using a state machine which I derived from the enemy behaviour script I had written previously. There are several states, IDLE, PURSUE, SHOOT, DEATH, SPAWN, FLEE, SHEILD, DETONATE. The detonate and sheild states are not used by the central piece of the boss. The spawn state is only for the central boss part. It spawns new drones and shields if there are less than 3 drones remaining and if it can see the player. It will not spawn new shields until there are no shields left. 
The boss in the prototype was very motionless. In the end the boss became much more agile and jumpy. I lowered the effect of gravity on it so that it could reach the higher platforms. It has a shield of small drones that circle around it which it cannot shoot through until the player destroys them. The separate drones that chase the player initially were just to get in the player's way. Now they explode after they hit the player. They also explode on death and take damage from the explosions which creates a chain reaction. This is because the drones only have 1 health. This caused me a problem to start because the boss spawns new drones when there are less than 3 remaining, and when they exploded as new ones spawn it creates a huge chain reaction of constant explosions above the boss. If the player enters this area they die instantly. I fixed this by making sure the drones take no damage from explosions for 0.2 seconds after they spawn. Now the problematic chain reaction no longer happens. 

I mentioned I made the enemy behaviour before the boss and derived the boss from that. My team wanted enemies that did were not fast and agile. However, we did want movement. So I made a script that made the enemy shoot when the player was seen, pursue in the direction the player was last seen and stop after a bit of time, and die when shot too many times. It was fun to figure out how I would do this and it took a little bit of looking up state machines and rigidbody velocity and addforce stuff. In the end I used a lot of what I already knew about code to make it. Unlike the boss I used a different script for each of the 3 enemies.

Here is a clip of the prototype of the boss.



No comments:

Post a Comment