Author Topic: HUD Text in the Asset Store  (Read 36392 times)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text in the Asset Store
« Reply #30 on: July 16, 2012, 02:41:53 PM »
The disabling of the HUD when it's off-screen should be your game code. Ideally you will want to have a root object that will do this, and this root object will have children, among which is your unit's health bar, any and all on-screen elements (such as Unit's name), and of course -- HUDText. This script will be enabling/disabling only children, leaving itself enabled at all times (otherwise it won't be able to re-enable itself after it gets disabled). This object will also have the UIFollowTarget script on it.

P.S. I'll add this in though, controlled by a boolean flag.
« Last Edit: July 16, 2012, 02:44:05 PM by ArenMook »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text in the Asset Store
« Reply #31 on: July 16, 2012, 02:51:17 PM »
http://www.youtube.com/watch?v=diql3UP1KQM

I forgot to boost the volume. Too quiet?

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: HUD Text in the Asset Store
« Reply #32 on: July 16, 2012, 10:13:53 PM »
It's a little quiet, yes.

Also, I had to mod UIFollowTarget with the following:

  1.                         pos = transform.localPosition;
  2.                         pos.x = Mathf.FloorToInt(pos.x);
  3.             pos.y = Mathf.FloorToInt(pos.y);
  4.                         pos.z = 0f;
  5.                         transform.localPosition = pos;
  6.  

This is to prevent the HUD item from jittering if the target object is sweeping through space with the camera rigidly attached.  Little rounding errors of the transform position make the calculated center bounce around +/- 1 pixel if using mathf.round().  Using FloorToInt or CeilToInt prevents that behavior.

catacomber

  • Guest
Re: HUD Text in the Asset Store
« Reply #33 on: July 17, 2012, 12:34:59 AM »
Thank you for the video tutorial-----a little louder would be good. But I was able to follow.   :  )  I was out without my computer today. Only just got a chance to watch it and download the updated HUD Text.
« Last Edit: July 17, 2012, 12:56:14 AM by catacomber »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: HUD Text in the Asset Store
« Reply #34 on: July 17, 2012, 10:21:06 AM »
Ok I will change it to be "FloorToInt" in the next update, thanks.

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: HUD Text in the Asset Store
« Reply #35 on: July 18, 2012, 12:34:22 AM »
EDIT:  Okay, I definitely need to get a better understanding of the coordinate system translations that are taking place, because the changes below definitely have some wonky behavior.  Ignore for now.


Aren, a bit of a correction, as just using Ceil or Floor doesn't fix it completely.  This does:

  1.             // prevent jitter by only moving the object if it's more than one pixel
  2.             if (Mathf.Abs(transform.localPosition.x - pos.x) > 1.5f || Mathf.Abs(transform.localPosition.y - pos.y) > 1.5f)
  3.             {
  4.  
  5.                             transform.position = _mUiCamera.ViewportToWorldPoint(pos);
  6.                             pos = transform.localPosition;
  7.                             pos.x = Mathf.CeilToInt(pos.x);
  8.                 pos.y = Mathf.CeilToInt(pos.y);
  9.                             pos.z = 0f;
  10.                 transform.localPosition = pos;
  11.  
  12.             }
  13.  

It's essentially making sure the delta in pixels in either the X or Y direction is more than one pixel, so that it doesn't jitter.  Might need a little more fine tuning.
« Last Edit: July 18, 2012, 01:35:13 AM by JRoch »

JRoch

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 140
    • View Profile
Re: HUD Text in the Asset Store
« Reply #36 on: July 18, 2012, 01:48:37 AM »
Alright, I think I understand the logic here.  Jumping the camera around was causing the UIFollowTarget script to act weird with the earlier mods because of the Z value not being compared.  Here's what I came up with:

Note:  _lastZPosition is a private float used to track changes in Z between cycles and determine if a significant change requires recalculating the position of the follow.

  1.             // prevent jitter by only moving the object if it's more than one pixel
  2.             if (Mathf.Abs(transform.localPosition.x - pos.x) > 1.5f || Mathf.Abs(transform.localPosition.y - pos.y) > 1.5f || Mathf.Abs(_lastZPosition - pos.z) > 1.5f)
  3.             {
  4.                 _lastZPosition = pos.z;
  5.                             transform.position = _mUiCamera.ViewportToWorldPoint(pos);
  6.                             pos = transform.localPosition;
  7.                             pos.x = Mathf.CeilToInt(pos.x);
  8.                 pos.y = Mathf.CeilToInt(pos.y);
  9.                             pos.z = 0f;
  10.                 transform.localPosition = pos;
  11.  
  12.             }
  13.