Visualizing player health without a HUD
|
In this weeks blog I would like to write about the task of trying to present the health of the players health without using a HUD.
The original plan for our project was to make a bullet hell-esque game. Because of this we felt that it would be necessary to show the amount of available lives directly on the players avatar to not divert the players focus. Since the our game revolves around absorbing the powers of different enemies, we felt it would be fitting to have some kind of spirit spheres circling around the avatar.
So basically there are an amount of orbs that equal the players health minus one, so that each orb represents one available. For the orbs to be able to rotate around the player I first give all the orbs a reference to the player. In the update function for the orb there is a private degree variable that represent the current angle that the orb has in relation to the player. This is done by creating a reference to the the players position and increasing the degree variable, and then using unity’s Mathf.Sin() and Mathf.Cos() functions on the degree. The value from these math functions are then multiplied with height and width variables set by the user, to morph the shape of the circle as the player is kind of oblong. The gameobject of the player holds a script containing an array of all the orbs and give all the orbs their start rotation in order for them to not all be placed on top of each other. Setting the start degrees, which is done whenever the amount of health changes, is done through a function. This function contains the following code, which loops through the array of orbs and only lets certain ones get rendered, as well as spread them out. for (int i = 0; i < orbs.Length; i++) The .setNewStartDegree((360f / (health – 1)) * i) function sets the angle to whatever angle is being sent in, and the parameters make sure that they are always evenly split, instead of clumping up towards one side once the player starts losing health. ![]() The reason we used sine and cosine is because we knew we wanted the orbs to move around the player in a circular motion. If we had instead wanted them to move along a more complicated path the method used most likely would not have been possible, with more time being spent on how to create paths inside Unity.
Lepa out. *mic drop*
|

