Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
DrowningMonkeys's avatar
DrowningMonkeys
Honored Guest
11 years ago

Best practice: healthbars

Hi guys,

Well I'm sufficiently frustrated trying to figure this out on my own so I thought I'd reach out here.

I want to add healthbars over my characters heads. In a normal situation this is easy. You convert world coordinates to screen coordinates. But because you can't use the "screenspace- overlay" canvas, I feel like this has gotten trickier.

One idea would be to use a "screenspace- camera" canvas, but the canvas would need to be perfectly snapped to the camera frustum. And I have no idea how to do that or if any other complications from doing that would arise.

I did try rendering a screenspace camera to a render texture and attaching the render texture to the center eye anchor. But because I couldn't snap it into place correctly, and also maybe because the render plane was not the right dimensions, the result was WAY off.

Has anyone successfully done this??

3 Replies

Replies have been turned off for this discussion
  • I'm sure it would be doable, not that i use unity so can't help there, but have you thought about using meshes instead (+hw instancing for alternate characters). not ideal I guess but would work as a placeholder till you figure it out.
  • So, typically that's what i would do, if i was starting from scratch or something, but you can't use Unity's UI stuff in real world space, unless every single healthbar had a separate canvas. But now I don't really know why I shouldn't do that, so I'm gonna give it a shot and see how it looks.
  • Well, I gave this method a shot, and it works great (reminds me of how Legend of Dungeon does its overhead text). It's not as elegant as translating the positions to screen coordinates, but definitely flows well with the VR look. So for anyone looking to do healthbars, what i did was take my regular UI sliders, and make them a child object of a world space canvas (a very, very tiny world space canvas), that i then attach over the head of an enemy or player. The canvas is responsible for scaling, not the slider object. So for example, my healthbar sliders are 100 units wide, and my worldspace canvas is 1.5 units wide with a .01 scale. There seems to be minimal performance impact. I really dont know what the negative impact is of having a zillion canvas's floating around is.