Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Rotation Radar

Discussion in 'Immediate Mode GUI (IMGUI)' started by Predster, Jan 23, 2008.

  1. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    I'm working in a project where the player will be navigating through a tunnel such as this:



    I've modifed the mouselook script (that comes with the FPS asset) so that the user can rotate the camera around, effectively spiralling through the tunnel.

    My problem is, the user needs to know their angle of rotation relative to the horizontal, so I'd like to make a little rotation radar (similar to in a flight simulator). However, I don't have Unity Pro and I can't use render textures. Is there anyway I could use a draw a GUI object (like an arc) that would change with the rotation of the camera? (I'm completely unfamiliar with all things GUI). Any suggestions on how I could accomplish this?

    Thnx
     
  2. phoen

    phoen

    Joined:
    Oct 25, 2005
    Posts:
    94
    i was working on a radar-like orientation aid some time ago.
    maybe you find it useful.
    the script is casting rays around its y-axis every frame, collects the hitpoints and tells the linerenderer to use these positions.

    just put it on a gameobject with a linerenderer (must have positions set to 180).



    Code (csharp):
    1.  
    2. function Update () {
    3.     Radar();  
    4. }
    5.  
    6. function Radar (){
    7.    
    8.     var layerMask = 1 << 8;
    9.     layerMask += 1 << 9;
    10.     layerMask += 1 <<11;
    11.     layerMask = ~layerMask;
    12.        
    13.     dots = new Array();
    14.    
    15.     for (x=0;x<180;x++){
    16.         var hit : RaycastHit;
    17.         transform.localRotation = Quaternion.Euler (0,x*2,0);
    18.         if (Physics.Raycast (transform.position, transform.TransformDirection (Vector3.forward), hit, 2000, layerMask))
    19.         dots.Add(hit.point);
    20.     }
    21.        
    22.     for(x=0;x<dots.length ;x++){
    23.     GetComponent(LineRenderer).SetPosition(x,dots[x]);
    24.     }
    25.     for(x=dots.length;x<180  x>1;x++){
    26.     GetComponent(LineRenderer).SetPosition(x,dots[1]);
    27.     }
    28.    
    29.     if(dots.length <=0)
    30.         GetComponent(LineRenderer).enabled = false;
    31.         else
    32.         GetComponent(LineRenderer).enabled = true;
    33.  
    34. }
    35.  
     

    Attached Files:

  3. Predster

    Predster

    Joined:
    Sep 11, 2007
    Posts:
    145
    Awesome!! Thanks!!

    Edit: But when you say positions set to 180, do you mean the coordinates or number of elements?

    I can't get anything to show up? When I set the positions to 180, I get an out of bounds error.