I’m working on a 3D isometric game that restricts information based on field of view (FOV). I already have code that can determine which cells / blocks can be seen from a given location. In the example shown, if a unit block hasn’t been seen by the player, I’m rendering an ‘unknown’ block in that location (the large ? blocks shown below) in place of the terrain (I.E. the node associated with that unit of terrain is not attached to the scene). If a block has been seen before, but is currently outside the FOV, the terrain is rendered along with a small ? marker.
This sort of works, but it doesn’t address anything else that might be occupying that space (enemies, particle effects, etc). In the example image, character 2 shouldn’t be able to see character 1, but should have some knowledge of what was last seen at that location. If it helps, currently each character & special effect has its own node.
An ideal solution would:
show previously seen terrain
indicate the area is currently outside the FOV
hide occupants that are outside the FOV
it might be nice if I had a way to show the last known occupants though
Currently, my best guesses are to either use some sort of shader to discard things out of the FOV or to manually attach & detach nodes by checking for collisions with the bounding volumes of out of sight blocks. I’m interested in feedback on these or other solutions. Thanks.
This makes me think I don’t really understand what you are trying to do. Objects outside the FOV aren’t rendered anyway. They are culled during render.
To make a ghost object (mark position where enemy was last seen) - just create a clone via spatial.clone() and then attach that to a new Node. Manage these Nodes via a collection (kick out objects if the real things are visible again - and you don’t need the ghost object anymore). Making transparent material is quite easy too.
Generally in these types of games, I see that ‘fog of war’ is based on the cells… almost like cellular automata type algorithms. That’s how I did it in Monkey Trap: cast a ray out to the cells see if there are filled cells in the way.
Yes, that’s what I meant - in retrospect I realize I was using overloaded terminology, sorry about the confusion.
I had totally missed setting the cull hint - that seems way easier than messing with shaders (which I know next to nothing about right now). I also like the idea of cloning ghost spatials provided that there is a way to change the transparency without changing materials - I’d hate to have to make duplicate materials for everything that might need ghosting.
@pspeed At an earlier point I had considered fog of war effects, but later on I wanted to leave the door open to having fog / smoke as an in game mechanic for interfering with line of sight / FOV stuff. The ray casting bit sounds very similar to what I’ve done. Does Monkey Trap do full 3D ray casting for fog of war or is it restricted to a single plane?
The levels are effectively 2D mazes… so it just casts in the maze and keeps track of which cells are visible and which aren’t. It then uses this to darken/lighten cells. Actually, it has two different levels of visibility… areas you’ve never seen are black and areas visited before but now invisible are grey.
Cool game. Mind migrating it to github?
Would this be a good way to explore Zay-ES and networking?
Also, the lighting effect is really nice.
Only thing that looks odd are those wall quads that sometimes jut out.
It was the test app for implementing Zay-ES networking… so probably.
The back sides of the walls are truncated so that you can see past them will still giving some impression that there is a wall there. After all, we are essentially seeing through solid matter.
I see … so it’s as intended. Only a steep angle could make this appear less obvious (like, for example, having a top-down-view like in the game that I want to make some day).
Just wanted to follow up - I roughed the set cull hint @Ogli gave & it works. Presently the spatials blink into & out of sight when their center of mass crosses the FOV boundary. I think I might be able to fix that by using bounding volumes rather than center of mass, but given that I’ve already got some great tips here, I’d be interested to know if anyone has other solutions I haven’t considered.
Thanks for the help & apologies for moving the goal posts.