x


Mini-Map Display

Hi,

What I would like to do is to display a Mini-Map that is smaller than my actual terrain. I would like to display the scaled down terrain as a non-moving GUI at the approximate coordinates: x = 960, y = 340, with width as 280, and length as 210 (pretty much the bottom-right hand corner of the screen).

To acheive this, I could scale the terrain down to roughly meet those values, but when it comes time to display a player indicator (the 2D texture) for as the player is moving, the coordinates do not coorrespond, in other words, it is inaccurate.

What I can do is just draw a GUI Box where I need it to be, scale down the position of the player and also the terrain to conform to where I want the GUI Box.

The code below is inaccurate

void OnGUI()
{
    //Scale the "Top-Down" View of the terrain down by 0.8f and 0.4f    

    GUI.Box(new Rect(Mathf.Abs(MyTerrain.position.x) * 0.8f, Mathf.Abs(MyTerrain.position.z) * 0.4f, 300, 225), "");    
    GUI.BeginGroup(new Rect(Mathf.Abs(MyTerrain.position.x) * 0.8f, Mathf.Abs(MyTerrain.position.z) * 0.4f, 300, 225));        
        //Draw our Player Indicator Texture (PlayerWidget) For when the Player Moves.        
        GUI.Label(new Rect(Mathf.Abs(PlayerPosition.position.x) * 0.3f, Mathf.Abs(PlayerPosition.position.z) * 0.3f, 200, 200), PlayerWidget);    
        //Try to draw a game object at a known positon on the terrain
        GUI.Label(MyGo.x, MyGo.z, 200, 200), GoTexture);
    GUI.EndGroup();

}

Edit -- How could I get game objects that do not move to show up accurately?

more ▼

asked Aug 16 '10 at 05:36 AM

lampshade gravatar image

lampshade
391 84 92 110

Posted this here so you would get a blue envelope. I commented on my post.

Aug 16 '10 at 10:50 PM Peter G
(comments are locked)
10|3000 characters needed characters left

2 answers: sort newest

I would suggest taking an above-terrain screenshot, and using that as a GUI texture. Then you can script it to rotate as the character rotates and have it zoomed in. If you want, then you can use Paint or something else to add the nonmoving objects. Hope that helps.

more ▼

answered Aug 19 '10 at 12:40 AM

Mentalist4006 gravatar image

Mentalist4006
120 17 19 28

I am unfamiliar with rotating a GUI texture. Could you explain to me how that's done?

Aug 19 '10 at 02:04 AM Peter G

Technically you can't rotate a GUI, but somebody found a way how to cheat. Here's two links for that:

http://answers.unity3d.com/questions/3561/how-to-rotate-gui-textures

http://answers.unity3d.com/questions/18209/individually-rotate-gui-elements

Aug 19 '10 at 10:56 PM Mentalist4006

Actually, that's something different altogether. GUI textures are completely different than GUI methods and classes. They don't even have a common parent (GUI is in the top of the hierarchy of its class). GUI Textures require more manual coding, but are better for performance because they are drawn fewer times each frame. So, to clarify, you cannot rotate a GUI Texture.

Aug 20 '10 at 12:36 AM Peter G

Edit, well I don't know what kind of internal base classes Unity has so they might share an ancestor somewhere, but the class reference doesn't show a common ancestor in any public apis. And I want to say good idea, and don't worry, it's a common mistake confusing the two. Here's the class reference. http://unity3d.com/support/documentation/ScriptReference/20_class_hierarchy.html

Aug 20 '10 at 02:39 AM Peter G

Well, as the URL said, you could make multiple versions of the same texture, but rotate it so you get the rotating crosshair via scripting.

Aug 20 '10 at 11:08 PM Mentalist4006
(comments are locked)
10|3000 characters needed characters left

I would avoid using GUI Textures for your player indicator when you also used a terrain for the map. Then, you don't want to use a scaled version of your terrain, because that will give you poor performance. Grab a screen shot of the terrain and apply it to a plane or cube then have a second camera that renderers only the plane/cube. Then place an indicator object such as a sphere or a plane on top.

You can scale the second camera's normalized viewport rect to have it fit in the shape you want. Then I would use the script I wrote in this tread to have your indicator line up with the player.

One last point is that if you use GUI for your mini-map, then I would make sure you whole mini-map is set up using Unity's GUI system. That way you can do the coordinate math without changing from world space to screen space.

more ▼

answered Aug 16 '10 at 12:59 PM

Peter G gravatar image

Peter G
15.1k 16 44 137

To take the screen shot, how would I remove displayed sound and lighting icons?

Aug 16 '10 at 07:27 PM lampshade

I would look into http://unity3d.com/support/documentation/ScriptReference/Application.CaptureScreenshot.html that webpage. In the Unity editor create a top down view of your terrain and use a button press to grab the screen, you will likely need to crop it into a square in Photoshop or Gimp or whatever.

Aug 16 '10 at 10:49 PM Peter G

Okay, I have the cropped image of the actual terrain mapped correctly (visable) onto a plane. A secondary camera is situated above the plane with the cropped texture. However, I don't understand how to place an indicator object "on top" as you describe it...Could you please be a little more specific?

Aug 17 '10 at 09:06 PM lampshade

1 problem is that the secondary camera dissapears when I press play, what I think is that the main Camera (which follows the player) takes over. If I could get the map to stay up (which is within the secondary camera's FOV) while having the first camera follow the player, I could then proceed to the player indicator.

Aug 17 '10 at 10:21 PM lampshade

The secondary camera is likely disappearing because the depth is being changed at runtime for either one of your cameras. By "place on top" I meant position an indicator mesh such as a sphere or plane above the terrain image plane. Actually though, the script will do that automatically so it is really just for visualization in the editor.

Aug 17 '10 at 10:50 PM Peter G
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3

asked: Aug 16 '10 at 05:36 AM

Seen: 3363 times

Last Updated: Aug 16 '10 at 05:58 AM