Search Unity

Camera orientation widget

Discussion in 'Editor & General Support' started by Game-Whiz, May 20, 2020.

  1. Game-Whiz

    Game-Whiz

    Joined:
    Nov 10, 2011
    Posts:
    122
    Hi,

    What's the simplest way to achieve something like Unity's own camera orientation widget, that appears in the Scene tab? I just need to show a particular camera's orientation in another camera's view.

    Thanks,
    Alex
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    Are you trying to draw the view frustum for the camera? Or just like the x/y/z directional handles?

    Either way, check out the Handles class: https://docs.unity3d.com/ScriptReference/Handles.html

    If you want to draw a view frustum and it's not built in, you can use https://docs.unity3d.com/ScriptReference/Camera.CalculateFrustumCorners.html twice (once at the near plane distance, once at far plane distance) to get the 8 vertices for the view frustum, then just draw the lines between them with Handles.DrawLine or DrawLines
     
  3. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
  4. Game-Whiz

    Game-Whiz

    Joined:
    Nov 10, 2011
    Posts:
    122
    I just want to draw the X/Y/Z directional handles. What I've done, is create a widget similar to Unity's (X,Y,Z lines), view it with another camera, copy the rotation of the view camera to the widget camera, and set the widget camera's position according to the inverse forward vector of the view camera times some magnitude.

    This works, but it feels like using Thor's hammer to hammer a nail.

    I want to to this in runtime, outside the editor btw.
     
  5. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,911
    I think outside of the editor you're pretty much stuck with using your own assets since Handles and Gizmos are, as you know, not available.