Search Unity

Circular Target Indicator

Discussion in 'Scripting' started by Cyrussphere, Mar 4, 2020.

  1. Cyrussphere

    Cyrussphere

    Joined:
    Jul 1, 2016
    Posts:
    129
    I am looking for a way to creating a circular directional target indicator. Not sure how many Elite Dangerous players are out there, but as an example they have a small Circle on their UI that points in the direction of a single selected target, if that target is behind the player the circle turns into a circular outline that moves in the circle in a backwards fashion.

    I'm assuming ill use a Raycast to the target and use a WorldToScreenPoint to put it on a canvas, and then detect if the object is behind the player and then perhaps reverse the X and Y with a different icon. But where I am really stuck is how to limit these icons to a circle instead of using the entire square canvas?

    If anyone has any ideas or suggestions on this it would be appreciated, Thanks!
     
  2. exiguous

    exiguous

    Joined:
    Nov 21, 2010
    Posts:
    1,749
    I would have a look into Transform.InverseTransformPoint. This gives you the position of your target in local coordinate space. Means if target is above/beyond, left/right or infront/behind you. Then calculate the angles and position of the icon acordingly. The angle between foward and the target direction gives you how far the icon must be placed out (probably with Sinus/Cosinus). Since Unitys built in angle methods usually give the smallest angle (direction independant) you probably need to make a case distinction in which octant of the coordinate system the target is.
    See here the post of podperson.