Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by shadbags · Aug 21, 2014 at 05:22 AM · mapminimapmapping

How to make a minimap by pixels without second camera

I'm doing a procedural, grid based game, and want to make my minimap by allocating each grid coordinate a colour. Then having the minimap show 1 pixel per grid coordinate.

The only game I can think of that does something similar is TibiaTibias Map

In the above picture, each square is one pixel and represents one tile on the map. All the different grass is just "Green" and trees are "Dark green". Roads / Dirt / stone are grey or dark grey. This then gets used as the minimap "texture".

It's also only discovered in a rectangle around the player (hence the ocean turning black) but that's optional and relatively easy.

I can't find any resources to work in this way.

How can I do this? The only thing I can work out so far is to have a C# section of code that uses image libraries to draw a PNG or other indexed image and load that image in as the map in x * y sized chunks. The actual world itself is procedural, so can't be known ahead of time.

Edit: More detail on question

How can I turn an array of values (or list, or any collection) such as

 20002002
 21112002
 20002002
 11111111

Into an image or texture that I can draw as 4x8 rectangle of pixels? (Or use as a texture for a poly?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image b1gry4n · Aug 21, 2014 at 06:01 AM 0
Share

I do something similar. Procedurally generated tiles and a $$anonymous$$imap, but I do use another camera for UI purposes.

You said you dont want a second camera so it depends on how you are going to display this map. Built into the UI? It also depends how your world is generated. Is the entire world generated at the start or is it generated tile by tile as the player travels?

The world I create in my project is all generated at the start. $$anonymous$$y $$anonymous$$imap reveals the tiles if the player steps on them.

The way I achieve this is:

-Each of my tiles have a "type" (Grasslands, forest, etc). This is helpful for the $$anonymous$$imap tile to know what it should display as its material. Grass = green, Forest = dark green, etc. This also allows me to create a single $$anonymous$$imap tile prefab and reuse it over and over, changing its "type"

-Each of my game world tiles are the same size (50x50)

-For each of the tiles I create a UI representation of that tile. In your case if you want solid colors, create a plane and put a green texture on it or however you want to display that tile.

-All the game world tiles are added to a list OnLevelLoad

-Since all my tiles are the same size (50x50) i can take that info and setup my $$anonymous$$imap tiles as a "duplicate". If i want a map that is 1/10th the size its just 50 * .1

-All of the tiles are then replaced with a "black" or "see through" material to signify they havent been explored.

-When the player explores a gameworld tile, that tile activates a Reveal(); function and changes the corresponding $$anonymous$$imap tile to its original material.

$$anonymous$$aybe not exactly what you asked, but its the way I have achieved a $$anonymous$$imap in a procedural tile-based world.

avatar image shadbags · Aug 21, 2014 at 07:25 AM 0
Share

That sounds close, but on a much larger scale. I want one:one relationship between pixel on $$anonymous$$imap = a 32x32 pixel tile.

avatar image b1gry4n · Aug 21, 2014 at 04:49 PM 0
Share

If you want a pixel per tile I would think you would want to create a new texture with the scale being your entire world.

Treat each tile like a pixel.

if you have a 50x50 tiled world (with each tile 32x32), you would have a 50x50 texture size. tile at position x: 64, y: 96 (or x:64, z:96 if your world is flat inside unity and is 3d) would be easy to get the pixel position. Just divide by the tile size, 32. set the pixel at 2,3 to the color of the tile you want revealed

I have never done this before, just a theory.

you may want to take a look at

http://docs.unity3d.com/ScriptReference/Texture2D.GetPixel.html

http://docs.unity3d.com/ScriptReference/Texture2D.SetPixels.html

http://docs.unity3d.com/ScriptReference/Texture2D.SetPixel.html

avatar image shadbags · Aug 22, 2014 at 04:52 AM 0
Share

Those links look promising.

I'm a little concerned with how much of a performance hit it might cause, as it mentions in the link, but I only need to call it once per hundreds or even thousands of frames.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by alebasco · Aug 21, 2014 at 05:39 AM

Creating the image once you have the data can be done via many different tutorials - but getting the proper data will be the hard part.

I see a couple of options -

  1. Raycast down at every grid position. This will be expensive, and you'll have to either do it all at once when the game loads (and put up a loading screen or something), or do it over time, while the player is moving around, doing a few raycasts per frame. Depending on performance of your game / how fast you move / how big your grid size is, this maay work.

  2. Have each object report its location, and type to a manager. This will only work if you have grid/voxel based objects, but would be much easier. Since you mentioned creating the world procedurally, you might already have some load time and could do this as you create each object, report the type and grid position to a manager.

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shadbags · Aug 21, 2014 at 07:27 AM 0
Share

$$anonymous$$y problem isn't getting the data (I can easily get whether the "top" tile is grass, dirt, tree).

$$anonymous$$y problem is how do I turn

 0011011010    
 0101101110    
 0111010101

Into a 3 x 15 rectangle of pixels that I can draw in Unity.

avatar image MrVerdoux · Aug 21, 2014 at 07:31 AM 0
Share

@shadbags, I don't know exactly how to do it, but it should be possible with .NET, check this namespace: http://msdn.microsoft.com/library/system.drawing(v=vs.110).aspx

avatar image shadbags · Aug 21, 2014 at 09:26 AM 0
Share

So I use C# native drawing to draw the bitmap, save it, and load it as the material for a poly drawn as part of the UI?

avatar image Eric5h5 · Aug 22, 2014 at 05:25 AM 0
Share

That doesn't really work in Unity; use SetPixels.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Suggestions about creating a big map 1 Answer

Assigning UV Map to model at runtime 0 Answers

Can I make an open world with this engine? 1 Answer

Drawing an overlay mini-map 6 Answers

Terrain normal map. 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges