Jump to content

Minimap/Map Mechanic


Phodex Games
 Share

Recommended Posts

Hi community,

 

I would like to talk about how to create a minimap. I made myself some thoughts latley how to realise a minimap. And I would like to collect some useful toughts here. I actually found a solution, so tell me what you think of it. It currently just works as a normal map, not as a minimap...

 

Maybe it is very complicated what I do but thats why I created this post. Ok so I will start explaining.

 

First of all I took a screenshot from the topview of my map. Out of this I made a simple Map, by exporting the shot to gimp or something similar. The important thing is that the map has the same propotions than the real map size. The main idea is to grab the players 3D Position and convert it to a 2D position fitting to the map size and displaying a rect at the converted 2D Position.

 

The conversion works like this:

 

I tell my script the real map size (you can find it out in the viewports) and the pixel size of my map. Because my map and the real map size are propotional, I can calculate a "minimap multiplier" by doing this calculation: real map size X / map size X = multiplier. Thats the first part of the puzzle I need. Second I would like to know where to draw the player start position on the minimap. Because I have nothing I can relate to, I create a "minimap origin" pivot in the scene setting it to the zero-point of our map (not the origin of the viewport!!). To convert the player start position to a 2D Vector we do the following trick explained by this code:

 

self.playerPos = self.entity:GetPosition()
local myPos = self.mapOrigin:GetPosition()
self.mapOrigin:SetPosition(myPos.x, self.playerPos.y, self.playerPos.z)
self.playerStartPos.x = self.mapOrigin:GetDistance(self.entity:GetParent())
self.mapOrigin:SetPosition(self.playerPos.x, self.playerPos.y, myPos.z)
self.playerStartPos.y = self.mapOrigin:GetDistance(self.entity:GetParent())
self.mapOrigin:SetPosition(myPos)

 

As you can see I move the map Origin to get the correct X and Y values for the needed 2D Vector. If you didnt forget to also tell the script where the map origin of the 2D Map is in screen space, then you can now draw the player start position correctly on your map. To calculate the movement of the player, better said his current position I do the following:

 

self.playerOffset = Vec2((playerStartPos.x - currentPlayerPos.x) * self.minimapMultiplier, (currentPlayerPos.z - playerStartPos.z) * self.minimapMultiplier)

 

Now you can correctly draw a rect on your map on the correct player position:

 

local minimapOriginX = context:GetWidth() * 0.5 - (self.mapSize.x / 2) + 50
local minimapOriginY = context:GetHeight() * 0.5 + (self.mapSize.y / 2) - 10
local playerX = (minimapOriginX + (playerStartPos.x * self.minimapMultiplier) + self.playerOffset.x)
local playerY = (minimapOriginY - (playerStartPos.y * self.minimapMultiplier) + self.playerOffset.y)
context:SetColor(Vec4(0,0,0,255))
context:DrawRect(playerX, playerY, 10, 10)

 

Tell me what you think of this method? If you have ideas how to improve my script just let me know. After I was recieving some help from the community I wanted to give something back. However I you think this is a very bad solution, I would be glad to know what other methods there are, I am just an amateur coder smile.png

Link to comment
Share on other sites

You could create a 2nd camera somewhere above the player and then render the camera to a texture. Something like this: http://leadwerks.wikidot.com/wiki:render-to-texture-security-cam

 

Yes I know this method as well. But it is much more ressource heavy because you need to render everything twice. I also dont like that the minimap looks like ingame graphic. You also have the disadvantage that you only can create square maps. I would like to have my minimap in a specific, editable design.

Link to comment
Share on other sites

Yeah, your method is how I would do it as well. The double rendering is too expensive, and you can customize object appearances better. Generally, you want things on your minimap to be highlighted (enemies, objects, players, etc.), which double rendering wouldn't be great at. I don't think I've ever seen an actual minimap done with the render to texture method, but I could be wrong. On thing you may want to think about though is avoiding too many draw calls to images though. I don't imagine it being an issue, but if you have hundreds or thousands of images in your minimap, you're going to be doing a ton of overdraw, and have performance issues there as well, but I would think that it's better than double rendering still. In those extreme cases, you would probably use a 2D array with some type of custom shader to do that, but for most games I don't see that being an issue.

  • Upvote 1
Link to comment
Share on other sites

Yes, but I think you dont have that much of drawn objects at the same time, this could maybe appear on a super huge open world map, and for a minimap you can just show nearby object. That question is how to make my map look like a minimap, and how to just show a part of the map. I dont know how this should be possible...

Link to comment
Share on other sites

Draw a minimap by hand yourself, then put it in the top right . Then you should only apply the area of the minimap where the player currently is . I dont exactly know how to do that but you would need to make your own method that only renders the pixels needed.

 

Then you get some points of your actual map ( top right and bottom left for ex.) and from their x and y coordinates you calculate the values where the player is on the minimap. That shouldnt be too hard to make. I have explained it as short as possible, you can ask me again in Detail

  • Upvote 1
Link to comment
Share on other sites

Well, I think I didnt 100% get what you explained, but the problem is how to just draw part of the map. So I have my whole map as an image file. But Leadwerks just offer the "DrawImage" function, how should I hide some part of the map?

 

Then you get some points of your actual map ( top right and bottom left for ex.) and from their x and y coordinates you calculate the values where the player is on the minimap

 

With this I should apply the "scrolling" of the minimap, that the map knows where the player currently is?

Link to comment
Share on other sites

Use this shader

Well, I think I didnt 100% get what you explained, but the problem is how to just draw part of the map. So I have my whole map as an image file. But Leadwerks just offer the "DrawImage" function, how should I hide some part of the map?

 

Use the shader located here: http://www.leadwerks.com/werkspace/topic/12537-drawing-a-section-of-a-2d-texture-setting-uv-coords/#entry90453

  • Upvote 2

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...