- Home /
Minimap - drawing the main Camera's projection zone?
Apologies for the vague title - to explain, I've got 2 camera's on my scene. One acting as a minimap in the bottom right corner, and then of course, the main camera for the player to control.
The game is a top-down RTS; and I'm trying to set up a system where the viewport of the main camera can be rendered on the minimap camera; ala, drawing a box around the map, where the main camera can see.
Any help would be much appreciated!
Answer by gfoot · Jan 25, 2014 at 07:50 PM
Use the ViewportPointToRay method on your main camera to get a ray for each corner of the screen; then project the rays however far you like, eg until they got something, or until they reach the ground plane.
The Camera.ViewportPointToRay documentation has an example of casting a ray through a pixel.
Use a big box collider for the ground, and Collider.Raycast (rather than Physics.Raycast) since you don't care if the rays hit a unit/ building/ whatever.
Hey,
Thanks for the suggestion - but the Raycast isn't what I needed, I actually need to draw a box around the actual viewport that the player is seeing.. for example, take a look at it here - I've mspainted on the box on the $$anonymous$$imap. I'm looking to basically have something like that :)
That square box is inaccurate; if your game is an angled top-down view and you want the "actual viewport," then the shape on the $$anonymous$$imap should be a trapezoid.
You would use the raycast hit points to place either the corner points of a line renderer, or (better idea) the 4 vertices of a mesh with a transparent png of your square overlay.