Jump to content

Drawing health bars


Rick
 Share

Recommended Posts

I've had this issue before and just let it slide but curious if people have ideas on how to fix it.

 

When drawing 2D health bars (or using Sprites it seems as well) when the camera is directly behind the character it looks centered just fine, but characters off to the side of the camera the bars don't look centered. The same idea seems to apply to Sprites where they don't look perfectly aligned when off center of the camera. I'm curious on ways to fix this. Number wise things seem to work out fine but visually it doesn't look right.

 

Code wise I take the character position (center of it's feet) and add a value to the Y value to move it up towards the head. Then I Project() that position to get the 2D position. Then I subtract 1/2 the width of the rectangle for the x value to center it and then draw. In the screenshot you can see I'm directly behind the Rick character and it looks fine, both 2D rect and sprite name, but off to the left you can see how things don't look aligned correctly.

 

It almost seems like to get it correctly you'd have to work with the final screen and then figure out where to draw things but not sure how one would do that (sounds like a post effect but seems odd to have health bars as a post effect and not sure of the issue of getting that post effect the correct data). Does anyone have ideas on how to get this to visually look correct?

 

healthbars.png

Link to comment
Share on other sites

I'll create a pivot for the character prefabs at the exact point where I want this but I would think that's the same point that's happening when I add the y value to the 3D position so if think I would get the same result when its projected to 2d right?

 

 

On a side note I would have thought projecting 3D to 2d would handle this fov issue.

Link to comment
Share on other sites

I don't doubt you and with the lines I see but for my own brain I want to explore this more.

 

Shadmars line doesn't seem to go straight threw his head. It looks like is out his back. Scaling up the y value in 3D space I would think should always make the line go through his head. If I place a pivot at his head vs starting at his feet and moving upward in 3D space to the exact same point of where the pivot would be then those 2 3D positions would be the exact same and projecting them should produce the exact same 2d point right?

 

So would another way of looking at this be that unique y scale values per character so that it goes up right to their heads be another way to fix it? I won't be at my computer for the rest of the day but just an exercise for my brain to understand this. With your line over Shadmar reducing the y value doesn't seem like it would ever go through his head but I'm guessing it would because of the perspective. So if we were to slowly draw that line base on slowly moving upward the y value is 3D space we would see it slanting to the left the higher we go? I'd that right?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...