top of page

Week 7 - Enemy Attack and Player UI

This week I focused on adding additional features to both the enemy and the player. I created a player attack lunge effect, an enemy health system and a player stamina system, both with their own UI image bar.

I began with creating the lunge effect. Researching online, I learnt that I had to create a parabola and couple this with Unity’s Lerp feature to accomplish this

The lunge references to enemy positions which are stored within an array in the player class. If the enemy is within a certain range of the player, the player automatically lunges towards to the enemy, dealing health damage to the enemy.

I created two temporary variables. The original and the enemy positions are stored here. I used a parabular to interpolate between the start position and the enemy position. The parabola functioned by starting with a float value of zero, incrementing the value until it reaches 1 followed by decrementing back down to zero again.

Unity’s ‘Lerp’ function moved an object from one positon to another using a value range of 0 and 1. At the starting positon, the time value is 0 and at the target position, the value is 1. Using the created parabular I could move the object from the start position to the target position and then back to the start position again.

Secondly, I created an enemy health system which would work with the lunge effect in removing health from the enemy.

The animal behaviour scripts aren’t attached to the animal gameobject themselves. Instead, a script for each unique animal is created. A certain number of each of these animals are then instantiated into the scene.

I created a health bar UI by adding a background image and an image over it which would represent the amount of health the enemy had. I set the image type to be horizontally filled. This would allow me to manipulate the visual representation of the bar. As the script was not attached the enemy itself I needed to create an array which searched for the name of the health bar attached the boid.

Using the image.fillAmount feature, I was able to manipulate the healthbar image fill amount. I then created funcationality for enemy damage. Here, I referenced the previously related score UI, which would display the amount of damage being done to the enemy on every hit. I created an equation which took a percentage of the healthbar image fillamount on every hit. The variable for the dmage percentage amount was declared in the base class.

In order to not do damage on every frame, I created a timer which would only allow enemy damage to be dealt once a certain number of seconds had passed after the previous attack.

Finally I created a stamina system which allowed the player to sprint over a short period. Using the same methods as the enemy health system UI I created another canvas and attached an image to it

Using Unity’s GetKey method I set the speed of the player to increase when the shift key was pressed. This in turn would deplete the image UI relating the player’s stamina.

I had a meeting this week with my supervisor. We discussed areas I needed to focus on. I was advised to work on my enemy state transitions whereby the enemies would only flee once their fear level was high enough. I would need to give additionally control the amount of stamina each enemy had. This stamina would deplete when enemy’s fled from the player.


Recent Posts
bottom of page