- Home /
fog of war/detecting exposed entities
I found this question: http://answers.unity3d.com/questions/7409/how-would-i-do-fog-of-war which solves the problem of actually rendering the fog, the issue I am trying to tackle now is that I need to be able to replace a spawn marker with an instance of a unit(not in itself a problem.)
This project is an rts with npc's who will using a combination of FPS and RTS unit ai. As such, I have found that I can only have about 130 instances of units across the entire 10km x 10km map (and thats before buildings,details,and combat scripts are added.)
What I need to be able to do, is to seed the map with approx. 7500 spawn markers which, when they are revealed as units lift the fog, will be replaced by fully-functional instances of units, which will in turn revert to markers if they have been obscured by fog for a period of time...and I just cant seem to find a way to accomplish this...
Any insight would be appreciated.
I see a bunch of solutions between that answer and the thread it links... in your case, what exactly is the fog composed of?
fair enough...I'm actually holding off on making it quite yet(just because I don't want to have to make it multiple times) but I think adding a plane on top and having the each unit raycast up to check and lighten verts....although the player will have a maximum of 25 units(plus vehicles) so I suppose if i were to simply add a spherical collider/radar to each player unit to activate the markers to spawn it wouldnt bog down the system...though I dont think it would work to cause the enemies to revert to their marker form...
also i may have to rethink placing a plane over the map....the map has quite a height variation and I allow for a very close (10m) viewing angle
Answer by cjmarsh · Jan 05, 2011 at 08:10 AM
It sounds to me like you have a very large group of items you need to break down into smaller manageable components in order to make your game run smoothly. I'd suggest breaking up your 10km2 map into smaller squares with their own box colliders, the size depending on the average area that is visible to the player. With a sphere collider around the player's units, the areas that would need to be activated would be relatively easy to script. You could then instantiate all of the spawn markers in each of the activated areas, each marker with it's own collider, script, raycast, or whatever you'd prefer for the fog of war mechanic. This would leave those areas not near the player empty and free up some processor power.
An alternative would be to have the smaller square areas defined as matrices comprised of coordinates where your spawn markers would be on the terrain. Basically turning your map into a simplified matrix of matrices such that only the relevant spawn locations are instantiated when the player is close by. A simple update script that calculated the distance from the player's units to the different areas would provide the means for indicating where and when the matrices of spawn locations should be instantiated.
While I like the idea of making smaller square areas, I don't think that would fit well with the project I'm currently working on. You led we to my current thought of implementing a hexagonal grid of sorts; each unit would activate the grid it occupies as well as the adjacent grid spaces up to its view range. Then it would simply be a simple script to spawn/despawn any enemy units in the grid spaces...the only issue I can see is that even if I allow 2m/grid space that'll be 50 million grid squares and Id really like to have a single check for both fog of war and spawn/despawn.
$$anonymous$$y suggestion to break your enemy units down into smaller groups (I said squares, but hexagons work just as well) was so that when the player is close enough the spawn/despawn script would be activated along with the FOW script. This is, of course, assu$$anonymous$$g you're using a raycast upwards from the enemy units? If so, from what I understand anyways, you'd only need to implement the raycasts when the spawn locations have been initialized in their appropriate areas.
As for the size of the hexagons... I wouldn't use that small of an area, simply because it would negate the advantage of splitting the spawns into groups in the first place. Try using a larger area and seeing if the number of spawn locations isn't too much for the average user's computer to handle; Even if most of the enemies are off-screen, they will only be using as much processing power as the raycast update requires.
Your answer
Follow this Question
Related Questions
RTS game - AI help 0 Answers
RTS dynamic formation width and length 0 Answers
Whats an efficient method for drawing hundreds of Health Bars etc. over units for an RTS? 2 Answers
Pathfinding and AI for an RTS game 3 Answers
RTS Grid and Pathfinding 2 Answers