Author Topic: Making Hudtext not follow camera.  (Read 2536 times)

Dengao

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 12
    • View Profile
Making Hudtext not follow camera.
« on: March 07, 2017, 10:18:57 AM »
Hey! i can't seems to wrap my head around how to make the hudtext entries stay still on the place it has been spawned.  :'(
Basically i want the text to stand still on the place my character got hit while my character is moving. 
in Update in hudtext:

   for (int i = mList.Count; i > 0; )
      {
         Entry ent = mList[--i];
         offset = Mathf.Max(offset, ent.offset);

         if (uiCamera != null)
         {
         
            Vector3 pos = gameCamera.WorldToViewportPoint(ent.instPos);

            // Determine the visibility and the target alpha
            int isVisible = (gameCamera.orthographic || pos.z > 0f) && (pos.x > 0f && pos.x < 1f && pos.y > 0f && pos.y < 1f) ? 1 : 0;
            bool vis = (isVisible == 1);

            // If visible, update the position
            if (vis)
            {
               pos = uiCamera.ViewportToWorldPoint(pos);
               pos = transform.parent.InverseTransformPoint(pos);
            
               pos.z = 0f;
               ent.instPos = pos;
               ent.label.transform.localPosition = new Vector3(ent.instPos.x, ent.instPos.y, 0);
               offset += Mathf.Round(ent.label.cachedTransform.localScale.y * ent.label.fontSize);
               
            }

         }



Thanks in advance :)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Making Hudtext not follow camera.
« Reply #1 on: March 10, 2017, 11:23:36 AM »
Assuming you can have multiple texts visible at the same time, you will need multiple HUDText entries spawned underneath your character -- one for each hit point. All text underneath a single HUDText element travels with it, while in your case you have multiple points.