Monday, 12 December 2016

Weeks 5 and 6


 The fifth week of this term was assigned for revisions and phase tests, so our work for the game took a break and all of our attention was directed towards the evaluations. This means that no important features were added to the game or no important updates were made.


 If in the fifth week I have not worked as much at the game, in the sixth week I have started to direct, slowly, all of my interest towards the game, so I was assigned by my team to the enemies of the game (two types of enemies to be more specific, a melee one and a ranged one). The sixth week's lecture influenced my work because we were taught how to create, animate and code a character for our game, we were taught how to use Adobe Photoshop, Adobe Animate and we learned new features in Unity and C#. 

 With all of this new information acquired I have started to work on the enemies, so I took the sketches done by me in the first week and scanned them. The next step was to draw them in Adobe Illustrator, I chose Adobe Illustrator because my team and I wanted to create a vector graphic (vector graphics is the creation of digital images through a sequence of commands or mathematical statements that place lines and shapes in a given two-dimensional or three-dimensional space) type enemy, in this way our enemies will look round and realistic. The second reason for choosing Illustrator over Photoshop is that Illustrator is better for creating images than Photoshop, Adobe Photoshop is used mainly for modifying already created images or graphics and in Adobe Photoshop, bitmap graphics (a bitmap graphic is composed of many pixels, being possible to edit each individual pixel ) are created, but this type of graphics can look a bit unsmooth, feature that I want to avoid in order to create the enemies as perfect as I can.


 Here you can see the enemies: 


The Melee one:




The Ranged one:




 After I drew the enemies in Adobe Illustrator, I had to import them in Adobe Animate to create the sprite sheet. To import them in Animate I had to create for every part of the body a symbol. Here you can find the sprite sheets of the enemies:






 After I drew the enemies and created the enemy sprite sheets, I had to start coding them. Firstly I imported the sprite sheets in Unity and I sliced them. After I have done that I created a prefab for each enemy and I started coding. The first script I wrote is the one for the health of the enemies, In the start of the script I declared a public variable Animator in order to access the death animation of the enemies, and then I declared two floats variables for the "enemyMaxHealth" (this is one is public because I want to be able to modify it) and for the "currentHealth". In the Start method, I set the currentHealth to be equal with "enemyMaxHealth". In the Update method, I declared a public Void function which basically is supposed to affect the enemy's health when the player attacks him. The "Debug.Log" function messages the Unity Console, where you can see and select the error message. This is useful for locating the object where the error occurs nad solve it. Inside the Void function, I declared an if statement which accesses the makeDead function if the "currentHealth" of the enemy if lower or equal with 0. In the "makeDead" function, I declared a "Destroy(this.gameObject)" because I want to remove and destroy the enemy after he dies.






 The following script is for the movement of the Melee enemy. This script is supposed to make the enemy flip and follow the main character when the player enters the box collider. In the beginning of the script, I declared two public variables one to determine the speed of the enemy and one to access the animation of it. I want to be able to adjust the direction that the enemy is facing, so I added a "public GameObject", in order to be able to make the melee enemy flip and follow the main character, after this I want to know if the enemy is able to flip, so I added a bool which is set to true. The next bool highlights the facing of the character, it is false because the Melee enemy is facing left. The next two variables instantiate how often can the enemy flip back and forth when the enemy is idle. For attacking, I added the following variables: I declared the "attackTime" variable because I don't want for my enemy to starting running to the player as soon as the character enters the box collider, I want to give a chance to the player to dodge the enemy as good as he can. The "startAttackTime" variable determines how much time does the enemy needs to wait until it will start to attack. The last bool emphasises is the player is attacking or not. The "enemyRB" is a reference to my rigid body and this will allow me to manipulate the velocity that this rigid body is acting at. In my Start method, I need to set up the rigid body and the animator basically, they are the initializations. In Update method I will determine of the enemy can flip or not. The first if statement in the Update method flips the character if the current time is greater than "nextFlipChance". If this happens I made the enemy to possibly flip by writing into an if statement a "Random.Range" which takes numbers from 0 to 10, and if the random function is greater than 5 (it can be any number because it is a percent chance) I want ti flip the facing of the melee enemy and then I write the flipFacinf function. The "nextFlipChance" sets the next flip time. Basically every 5 seconds there is a possibility for our enemy to flip. The next thing I did was to start working on the actual code for flipping, so I declared a new method called "void flipFacing()". The first thing that I want to do in this method is to see if the enemy can flip because I do not want him to flip while he is running to the player, that is why I wrote the if statement. If the melee enemy is able to flip, the game object will access the "float facingX" variable which flips the enemy on the X axis,  "facingX *= -1f;" means that whatever the local scale for the X is, it flips in the negative form, after declaring the flipping variables I want to apply all of them to the graphic itself. The last thong I did in this method was to change the original bool. This is basically all the flip function.

 After I was done with the flip function, I started coding the following function, basically what I wanted was to create a certain function which influences the enemy in a certain way as long as the player is in the enemy's box collider. The first thing which I have done was to make the melee enemy to flipping and face the main character, so I created a new method called "void OnTriggerEnter2D" in which I determined, with the help of an if statement, if the game object which entered the collider is whether the enemy or something else. Is the game object is our player and if the enemy is facing the player I want for the enemy to keep its idle state, if the melee enemy is not facing the player I wanted to make him flip. So in the if statement I am searching for the player's position. Basically, the if statement is affirming that if the player's X position is less than the enemy's X position the game object needs to flip towards the position of the main character, for the "else if" statement is the same methodology, the only thing which is changed is the facing of the enemy. As soon as the player entered the danger zone the enemy will not be able to flip anymore and I want to determine when the enemy will be able to run towards the player. For the player staying in the "zone", I declared another method called "void OnTriggerStay2D" in which, if the player stays in the box collider the enemy will start running towards him. First of all, I wanted to check if the game object is still the player and if it is the program will check if the attack time is less than the actual time. If it is the enemy will start running to the player, if the enemy is facing left I wanted to increase the velocity in one way and if it is facing right I increased the velocity in the other way. The last thing I wanted to do on this method was to update the bool which starts the animation of running.  In the "void OnTriggerExit2D" method, I coded what happens if the player exits the box collider. The first thing I have done was to check, once again, if the game object is the same. If the player left the box collider means that the enemy will enter the idle state, it means that the game object can flip, "canFlip = true;", and it can't run towards the enemy anymore, "attacking = false;". Once the player left the "danger zone", I changed the velocity to zero. The last thing I wanted to do was to change the animation of the character back to the idle.









 Features that I need to work on: One of the only features that I did not manage to make it work was the attack animation. The rest of the code block is working properly but when the player enters the box collider and the enemy is running towards the main character, the melee enemy is supposed to play an animation and give damage to the player. Unfortunately, I didn't manage to solve it and instead of trying to fix the code for animation I programmed the enemy to start giving damage to the player as soon as the enemy touches the main character.


No comments:

Post a Comment