Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Skyrim-style compass in the UI

Discussion in 'UGUI & TextMesh Pro' started by ATLAS-INTERACTIVE, May 27, 2015.

  1. ATLAS-INTERACTIVE

    ATLAS-INTERACTIVE

    Joined:
    Mar 3, 2014
    Posts:
    1,421
    does anyone know how to create a Skyrim style compass in the new UI?
     
  2. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    556
    In theory:
    • You have a bar representing Xº, let's say 360 for completeness.
    • You know what rotation of your player corresponds to north, let's say 0º.
    • This then means that the left side (t = 0) represents -180º, and the right side (t = 1) 180º.
    • (Because the marker can't be in two places at once, one side will "actually" represent (-)179.9999999...º.)
    To find t you can then simply do something like: t = (player.transform.eulerAngles.y / 360f + 0.5f) % 1

    Once you have t, you can use it to find the correct position for your marker. For example:

    Code (csharp):
    1. float centerX = Mathf.Lerp(bar.anchorMin.x, bar.anchorMax.x, (player.transform.eulerAngles.y / 360 + 0.5) % 1);
    Adding the bar and marker should be fairly straight-forward from there I think. =)

    Hope that helped a bit, cheers!
     
  3. Rarceth

    Rarceth

    Joined:
    Oct 15, 2015
    Posts:
    41
    This is an awesome solution, however it only works for north. Say if I were to have a set of enemies, and a little red dot marker for each of them, how would I adjust this to point at them?

    Most of what you have there is fairly simple to reverse engineer. Use mathf.lerp to find the point between the two x anchors. The point itself? Get the bearing, divide by 360 to bring it down to a 0-1 range. Not sure why you add 0.5 or get mod 1 though!

    I know this is a bit of a necro, but im not seeing much else anywhere