Author Topic: How do I create a 3D rts style health bar?  (Read 6125 times)

storm33229

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
How do I create a 3D rts style health bar?
« on: December 01, 2012, 08:51:22 PM »
Well actually I want it to be hearts instead of a bar. I already have a 2D hearts UI for my character, but I'd like to create one for my enemies too. I've created a 3D UI, and dynamically created some sprites and attached them to the panel, the trick is to position them appropriately on my characters which I have not yet figured out. They also have to rotate to face the 3d camera too, sort of like a billboard sprite. One example of what I am looking for can be seen in Windward...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do I create a 3D rts style health bar?
« Reply #1 on: December 02, 2012, 09:45:59 AM »
Windward has a 2D HUD. Unit HUD is a prefab containing HUDText, unit's name (label), and a pair of sliced sprites showing health. This prefab also has a UIFollowTarget script on it. Both UIFollowTarget script is a part of HUDText package available for sale. If you do a search for it here, I've actually posted code for UIFollowTarget in the past.

storm33229

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: How do I create a 3D rts style health bar?
« Reply #2 on: December 05, 2012, 11:17:07 PM »
Since I absolutely love NGUI, I am off to purchase that package right now! Sorry for getting back to you so late on this - I think I forgot to subscribe to replies...  ::)

storm33229

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: How do I create a 3D rts style health bar?
« Reply #3 on: December 06, 2012, 12:19:31 AM »
I am having some trouble getting this to work. I've attached the HUDText and UIFollowTarget components to the sliced sprite (heart) in my UI, but the sprite is not following the object appropriately.

storm33229

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Re: How do I create a 3D rts style health bar?
« Reply #4 on: December 06, 2012, 12:28:22 AM »
...it usually helps if I follow the instructions and use a 2D camera instead of a 3D one... Anyway, it works now, thank you so much!

BABABLACK_911

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 2
    • View Profile
Re: How do I create a 3D rts style health bar?
« Reply #5 on: July 04, 2014, 06:08:41 AM »
Windward has a 2D HUD. Unit HUD is a prefab containing HUDText, unit's name (label), and a pair of sliced sprites showing health. This prefab also has a UIFollowTarget script on it. Both UIFollowTarget script is a part of HUDText package available for sale. If you do a search for it here, I've actually posted code for UIFollowTarget in the past.


Is there any way to do it without the HUD text plugin?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How do I create a 3D rts style health bar?
« Reply #6 on: July 04, 2014, 02:40:14 PM »
I mentioned I posted the code for it before. You can still find it if you search for it, or you can just do math yourself. Knowing the 3D point, use the game camera to transform it to screen space (camera.WorldToScreenPoint). Now knowing the screen space, use the UI camera to transform that position to world space (camera.ScreenToWorldPoint). Now inverse transform this position to be relative to the panel you want it to be a child of (panelTransform.InverseTransformPoint). Last step is to set the widget's transform.localPosition to that value.

It's all math, all Unity, and not really an NGUI question, but there you go.