Author Topic: Fog of War with UIFollowTarget  (Read 2146 times)

mdridley

  • Guest
Fog of War with UIFollowTarget
« on: November 12, 2013, 10:12:21 PM »
Trying to figure this out and just feel lost. I think I want to use the IsVisible for the UIFollowTarget to get the other player's name to show/not show based on distance from the player... but just cannot figure out where to start. Ideally would love to fade it in as you get closer, but fine with just doing the above.

I am guessing I need to set the x/y but not sure where to start with it.

Here is what I have tried so far... but I think the distance / position stuff is completely off
  1.                 Vector3 gamePosition = gameCamera.WorldToViewportPoint(target.position);
  2.         Vector3 uiPosition = uiCamera.WorldToViewportPoint(mTrans.localPosition);
  3.  
  4.                 // Determine the visibility and the target alpha
  5.                 bool isVisible = (gameCamera.isOrthoGraphic || gamePosition.z > 0f) && (!disableIfInvisible || (gamePosition.x > 0f && gamePosition.x < 1f && gamePosition.y > 0f && gamePosition.y < 1f));
  6.  
  7.         //Make disappear if too far away
  8.         if (isVisible) {
  9.             var distance = Math.Sqrt(Math.Pow((uiPosition.x - gamePosition.x), 2) + Math.Pow((uiPosition.y - gamePosition.y), 2));
  10.             Debug.Log(distance);
  11.             if (distance > 70) {
  12.                 isVisible = false;
  13.             }
  14.         }

Any help would be much appreciated. Thanks!
« Last Edit: November 12, 2013, 11:05:51 PM by mdridley »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Fog of War with UIFollowTarget
« Reply #1 on: November 13, 2013, 08:16:14 PM »
Not sure what you're doing with the distance there. Your post talks about fog of war, but you are comparing distance... that happens to be in view space which is 0 to 1 range. How can it be > 70?