Fog of war implementation in multiplayer and its difficulties
Hi,
I'm working on a RTS prototype and am trying to implement an optimized and clean Fog of War. The main issue I'm having is regarding the multiplayer implementation, i.e. proximity-checking for units, and runtime instantiation of units when they "appear" on a client's screen.
The basic concept
The camera hovers at a distance from the ground, and can move freely on the (x, z) plane (basic case: y/height is ignored for now).
Between the camera and the ground floats an opaque, black-texture plane. Its position is tied to the camera's, and the plane's texture is updated in real time with a shader.
The units lie on the ground, below the plane. They are either visible, or not (boolean state), and aren't affected by the opaque plane.
The issues
Multiplayer implementation
Since the game is supposed to go multiplayer at some point, there is a security issue to handle : the client doesn't know where the enemies units are, until they enter one of their units' view radius.
My guess is that the server sees every unit in the game, all the units have circle colliders, and whenever there is a OnCollision/TriggerEnter, it does the relevant checks (height comparison, mainly), and if the unit can see the other unit, the FoW manager of the client is notified.
I have two issues with this:
First, regarding the "circle collider" method: how optimized is it? What is the most efficient way of getting a notification when two entities get close to each other? The game could have around 600 units at the same time, so this part is important.
For security reasons, the client has no idea where the enemy units are, until the server tells him. Client-side, what actually happens to the enemy units when they don't see them? They don't exist? What happens when the server tells the client "Hey, there is a unit there!"? Is the unit instantiated at runtime, with its current animation/position/health/etc?
Height implementation
Looking at modern RTS, you can usually zoom the camera in very close to the units. The camera ends up being around the same height as the units... Which means that there is no such "opaque plane".
Do these games use some sort of volumetric fog? How do they implement their FoW?
Thanks in advance for any help.
Answer by nico_st_29 · Apr 28, 2020 at 01:40 PM
Did you ever get an answer to this? I'd be interested too.
Your answer
![](https://koobas.hobune.stream/wayback/20220612154230im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Having 5k+ gameobject 2 Answers
How to make a 2D fog of war? 0 Answers
How can I make fog of war area until player object visits? 0 Answers
Make Fog of War for 2D game !!! 0 Answers
How to make the 'Black Zone' in map (like the Fog of war) 1 Answer