Percentage Shield Bar

 Author: Jymeer Wilkins


Problem: 

A problem that I ran into was for our percentage shield. Whenever we picked up the shield pickup, shield equivalent to 20% of our max health would be added to our health bar. I already knew that I would probably do the shield part of the bar by having a separate bar behind the original health bar, but actually setting up was a little more difficult than I thought. Getting the shield bars percentage wasn't hard. It would just be the: (current health + shield health) / max health. Setting the health's percentage was my problem. As long as the health was lower than the max, the shield would show on the bar, but if the health was at the max, it completely covered up the shield bar.



Solution:

So for me to fix this, I had to change the way I set up the health percentage. As long as the health was at the max amount, it would always cover the shield, because I was setting the percentage by dividing the current health. I decided to change the health percentage to be: (current health + shield health) / current health. This solved my problem, but also created a new one. Setting the percentage like that would only work if the current health plus the shield was greater than the max health. So I decided to do an if check. If the shield plus the current health was over the max health, then I would set the percentage using:  (current health + shield health) / current health. If not, then I would set the percentage using: current health / max health. This fixed both of my problems.



 




Comments

Popular posts from this blog

Procedural Generation - Room NavMesh Spawning

Powerups and Wall clipping