2

I am making a space racing game in unity where the race tracks are tunnels which have intricate 3d paths. I want to create an HUD element which gives the player an idea of where she is on the track. I cannot do this by showing only a 2-D projection of the track in the HUD - I need to display the track in 3D.

Let's assume the whole track is one mesh. One idea I had is to create a game object copy of that mesh in a very small size (apply a simple translucent material/shader), and place that object visible in the corner of the camera, as its child object. My problem is that the track can be very large, and I only want to display a part of it at any time. A 3-D masking solution would be perfect - I could use a sphere as a mask.

Is there any way to do this? The nearest thing I found was an UI mask, but that only works on objects on UI canvas, and I can't put a mesh there.

Thanks!

Aman
  • 639
  • 1
  • 9
  • 25
  • 2
    u can use RenderTexture. The concept is that you'll have a camera rendering your UI canvas and putting the render output into a texture (RenderTexture) that you can assign to a plane in 3D. Google it, it's cool. This requires Unity pro, though. – Nika Kasradze Apr 14 '16 at 08:39
  • 2
    @NikaKasradze RenderTexture is also included in the free version. –  Apr 14 '16 at 10:12
  • [lol I'm getting old](http://docs.unity3d.com/ScriptReference/RenderTexture.html) I guess, [it was a pro feature in 4.x versions](http://docs.unity3d.com/460/Documentation/ScriptReference/RenderTexture.html) )) – Nika Kasradze Apr 14 '16 at 10:22

1 Answers1

2

If you want to create a 3d gui you can simply add another camera. You can duplicate the mesh as you describe and put it on a a particular layer(call it whatever you like). In your second camera lets call it the hud-camera you would set its culling mask to render only your custom hud layer. You should also set the clear flags to be depth-only. Finally you should set the hud-camera's depth to be higher than the main camera. This way the gui renders ontop of the game. Now you are free to scale and position your mini-track relative to the hud-camera. To ensure that the main camera doesnt also render the mini-track you can set the main cameras culling mask to omit the custom hud layer. I hope this helps.

computer_user
  • 61
  • 1
  • 6
  • and when he says "higher than the main camera" this is pretty easy. The main camera seems to default to -1, so any greater value works. – Mutant Bob Mar 16 '18 at 13:59