Search the Community
Showing results for tags 'Mechanics'.
-
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
-
So, I'm creating a blog to show how I'm approaching certain things (maybe this will be helpful to some people?). Stealth: This is a set of features that I wanted to go all out on, so that's what I'm doing right now. Shadows: Someone asked about how to implement shadows, and Josh gave a simple answer (kind of made me feel dumb lol). Anyway, the implementation for my game works for directional lights (the sun) right now, but it should be easy to extend to other lights if I choose to. Anyway, the way I calculated whether a point is in a shadow is by performing a raycast to the a vector generated by the light's rotation and scaled so that there would virtually be no building tall enough to evade the raycast. Crouch: This was pretty simple. The character controller needs to be changed using SetInput(), and the camera height needs to be changed while in crouch mode. That's it. Cover (Bushes): This was simple as well. I just performed a distance calculation to check if the player is near the center of the bush. Distractions (Rock): The AI doesn't actually "hear" the sound. Basically, each time the rock makes a sound, the rock the location of that sound is recorded and if it's close to enemy, the enemy will follow it. Buildings: I'm not sure how exactly I want to handle navigation due to building placement. I saw that there are recast commands accessible via C++, but I like to use Lua so hopefully these will be exposed through Lua in the future . But for now, these buildings have physics attached to them that scale as the building is constructed. Sounds: I sort of organized this like how a radio plays. When one ambient track finishes, another picks up. The way a randomly select the next track is by using the player's position data, but I found a way to change this in the future by using the system's milliseconds instead, but I don't know what to use! Day/Night: I wrote my own Day/Night script (I tried to use Shadmar's implementation, which is much better than mine, but I my weird lighting preferences made the colors of everything mess up). Anyway, it's simply a directional light that changes as time changes. Also, the ambient light changes as well so that the night becomes VERY dark! So, you must use your flashlight or find light!
- 2 comments
-
- 4
-
- Built from Ruins
- stealth
-
(and 1 more)
Tagged with: