Alright, I know this seems like a simple math question, and to be perfectly honest, it is, but I for some reason cannot think of it right now, and my deadline is in a week and a half. Here’s the question: I have a mob, as well as it’s health bar, above it’s head and I need to center it on the mob. The first thing that comes to line is healthBarX = x + (healthWidth / 2) ; but obviously this doesn’t work because if the mobs health bar is longer than the width of the mob than it is wayyyy to the right. I know, silly question but help is very much appreciated
-cMp
Just to clarify, does the bar need to be recentered every time its health gets smaller? Maybe a picture of the bar could help
Can’t you just put a red bar under the green bar? Red bar standing for max health and green bar standing for current health?
Yes that could work. Are you using any library with this? Either way this question would persist.
Screenshot please?
Assuming upper-left origin for rendering entities:
float barX = (entityX + entityWidth/2f) - barWidth/2f;
float barY = entityY - BAR_SPACING;
I have the bar set up to be as long as the mobs health is. e.g, if the mobs health is 100, the bar is 100 px long. So I think davedes suggestion will work, props to him if it does, otherwise I will set it up to be a static length for all health and adjust to that.
Davedes idea worked perfectly! Thank you very much, i am in love with this forum!!