I want to dedicate this post to something that has been bothering me for awhile. Why? Because it has really simple solution and yet for some reason it is grossly overlooked by some major game developers. I’m talking about rounding the remaining health and displaying it as percentage integer from 0 to 100.
So what is the problem? If you apply generic rounding to one’s health you are risking to frustrate players big time especially when you give the killed feedback on the status of his killer. In popular games like Battlefield Bad Company 2 for example, seeing your killer getting away with 0% health could be pretty irritating.
One of the reasons this could happen is because when player health is below 0.5, your usual rounding function will return 0 while the player is still alive. This is understandable if you know how math works but an average player neither knows nor needs to know any of that. For the player 0 means dead, period.
What would have been better in this case is to show 1% instead. Using ceil function instead of round would solve this particular problem as it would round even the smallest value like 0.00001 to 1%. But this would create another problem with killer showing 100% even though you know you hit him. 99.00001 health would display as 100%. This is equally frustrating if not more. Even round function cannot be used here because 99.5 health will also show as 100%.
The solution is to use ceil for under 1 health, floor for over 99 health and round for the rest. And this is what I did, only I also normalised the range so that the cumulative health is never more that 100 or less than 0. So you can add and subtract health value as much as you want but when you pass it to my function you should get a fair representation of one’s health. And if my function returns 0, your player is better be dead at this point .
Here how it looks in SQF:
And I just thought why not to throw in a C++ version as well for comparison: