Author Topic: Occluded health bars  (Read 5225 times)

sirival

  • Guest
Occluded health bars
« on: May 02, 2012, 04:18:57 AM »
Hey there,

I have a working prototype for health bars showing above player names. These work fine however since I am updating their position by using worldCamera.WorldToViewportPoint and then guiCamera.ViewportToWorldPoint the health bars are not located at the actual position of the players so they are not occluded by the level's geometry.

I have tried various things to solve that without success. This includes the method described in this post: http://answers.unity3d.com/questions/187543/draw-orthographic-visuals-eg-health-bar-in-perspec.html but I could not get it to work.

The latest thing I am trying is parent the health bar as a 3D plane under each player, make it a billboard and also adjust its scale to stay the same depending on the distance from the game camera.. However I am hoping to find a better solution that this one if possible.

Any ideas?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Occluded health bars
« Reply #1 on: May 02, 2012, 08:19:28 AM »
You know there is a sticky post here titled "So you want to make health bars...", right?

http://www.tasharen.com/forum/index.php?topic=130.0

sirival

  • Guest
Re: Occluded health bars
« Reply #2 on: May 02, 2012, 08:24:38 AM »
You know there is a sticky post here titled "So you want to make health bars...", right?

http://www.tasharen.com/forum/index.php?topic=130.0

That is what I first read to create the prototype. That post does not mention anything about occlusion though. And if you run your demo you will see that health bars are rendered on top of that wall in your scene...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Occluded health bars
« Reply #3 on: May 02, 2012, 08:26:49 AM »
Ah. Just make a child object right above your game character, and attach a UIPanel to it (same layer as your character). Add a label child to the panel with the name. Add a script to the panel that will scale the tag based on distance to the camera if you want. Then add code to your script that will always make this name tag face the camera.

sirival

  • Guest
Re: Occluded health bars
« Reply #4 on: May 02, 2012, 08:29:03 AM »
Thanks, yea that is what I have been trying to do... The problem is that it doesn't look that good! Thanks for the help though!