Monday, April 5, 2021

Creating a (mini)map

How can one play a game with such a big map without the help of a minimap? - time to start working on that.

Today I will be creating the base for the minimap, I'll first be mapping out the terrain of the world - buildings and all that will come a little later on.



To color the terrain I just need to sample the game world by the relative coord on the minimap(I made the minimap resolution work per chunk so you'll get the same "pixel per hex" on different map sizes), sounds pretty simple in theory - and luckily this time it is.

I can easily convert the texture [x,y] pixel coord to hex grid (same math used for the mouse position) -> get a hex -> get the texture index for the terrain -> get the terrain texture from the texture array I use in the terrain shader -> average that and stick it in the minimap [x,y].

Viola - minimap!


Oh right... the water... doh!

Ok, so let's say that if a hex is underwater we'll lerp the color to blue-ish by how deep the water is from 1-16 elevation steps


well.. had a feeling the low end won't be enough, maybe we'll force it to be atleast half blue?


Ah - that's better!
Still could use some tweaking though, and I don't think a simple square/inverse square will do.
Time to whip up my favorite solution - AnimationCurve!


It's a subtle change, but I think it's much smoother.

I forgot to mention, those minimaps are on a 35x35 map with a resolution of 8x8 per chunk, here is the same map with different resolutions going from top left to bottom right (1x1, 2x2, 4x4, 8x8, 16x16, 32x32)


I know you can't really see a difference between 8x8 and higher, but I'll be adding a zoom function so that'll be useful then.

You know what? why wait, let's do that now, I think all I need is a ScrollView and a slider.

Here's the difference between 8x8, 16x16, 32x32 and 64x64 - left to right, bottom zoomed out, top zoomed in. (I moved them aside a bit so you can see the area they're zoomed onto)


One thing I think we can add is the clouds, should be simple enough, just like the water - only this time lerping to white instead of blue.


It's a start, I think we can call our good friend the AnimationCurve once again.



Maybe I'll play with the curve a little more, but it's much less aggressive.
 
I think that's good enough for now, when the rest of the game comes a bit further along I'll add in faction-colored building,
I'm thinking about how to display terrain height on the minimap,
Also wondering if and how to add the plants too.

I still need to save a minimap for each map along with the map data to display on the loading menu fast, but I think I'll do that tomorrow - I've spent most of the day working on the UI code and creating a main menu (nothing interesting to hear about) and it's getting late!

And a camera indicator with a click-to-move functionality should also be good, can't forget about that one.



Thanks for reading, and check back soon for more, the next video log should be ready soon along with the next test build!

No comments:

Post a Comment