Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Feature Request How to create a Fog of War System for a 3D Space RTS Game.

Discussion in 'Scripting' started by JayTi-JayFiArts, Sep 27, 2023.

  1. JayTi-JayFiArts

    JayTi-JayFiArts

    Joined:
    Jun 4, 2021
    Posts:
    5
    Hi,
    I am currently developing a space real-time strategy game.
    I've looked at dozens of tutorials on Google, but they are often outdated or based on a projector, the problem is that I don't have a visible ground in my game, which is set in space. I want to use render textures for my Fog Of War. The Fog of War should work like in Age Of Empires.
     
  2. Nad_B

    Nad_B

    Joined:
    Aug 1, 2021
    Posts:
    303
  3. JayTi-JayFiArts

    JayTi-JayFiArts

    Joined:
    Jun 4, 2021
    Posts:
    5
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,561
    Ground or not doesn't matter to fog of war. It's a covering that prevents you seeing the game, nothing more.

    Fog of war also doesn't strictly require a shader. You could always make your own geometry or add sprites to cover the fogged area.

    Start with some tutorials. There's enough moving parts to ANY fog of war implementation that nobody is going to retype them successfully in this little box.
     
  5. JayTi-JayFiArts

    JayTi-JayFiArts

    Joined:
    Jun 4, 2021
    Posts:
    5
    I dont want to use geometry, because i have a big map and many units that are updating the fog of war.
    I watched like 20 tutorials with render texture but they used a projector (which requires a visible ground) or a plane and a shader but I dont know how they make the visible parts transparent, it doesnt work and I think its because they are outdated(9 years old). If you have a good tutorial for a fog of war for a space rts game in 3D which is not to performance intensive, pls send it to me.
     
  6. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,561
    "Watching" tutorials isn't useful to anyone, except perhaps the guy who gets the Youtube clicks.

    Try this approach instead. Pay particular attention to Step #2... which will give you the knowledge you need to engineer a solution suitable to your specific needs:

    Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

    How to do tutorials properly, two (2) simple steps to success:

    Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That's how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

    Fortunately this is the easiest part to get right: Be a robot. Don't make any mistakes.
    BE PERFECT IN EVERYTHING YOU DO HERE!!


    If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

    Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.

    Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

    Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there's an error, you will NEVER be the first guy to find it.

    Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

    Finally, when you have errors, don't post here... just go fix your errors! Here's how:

    Remember: NOBODY here memorizes error codes. That's not a thing. The error code is absolutely the least useful part of the error. It serves no purpose at all. Forget the error code. Put it out of your mind.

    The complete error message contains everything you need to know to fix the error yourself.

    The important parts of the error message are:

    - the description of the error itself (google this; you are NEVER the first one!)
    - the file it occurred in (critical!)
    - the line number and character position (the two numbers in parentheses)
    - also possibly useful is the stack trace (all the lines of text in the lower console window)

    Always start with the FIRST error in the console window, as sometimes that error causes or compounds some or all of the subsequent errors. Often the error will be immediately prior to the indicated line, so make sure to check there as well.

    Look in the documentation. Every API you attempt to use is probably documented somewhere. Are you using it correctly? Are you spelling it correctly? Are you structuring the syntax correctly? Look for examples!

    All of that information is in the actual error message and you must pay attention to it. Learn how to identify it instantly so you don't have to stop your progress and fiddle around with the forum.
     
  7. JayTi-JayFiArts

    JayTi-JayFiArts

    Joined:
    Jun 4, 2021
    Posts:
    5

    I've been developing for about 3 years now and have never asked a single question, I've always solved everything myself, this time after 2 weeks I still didn't have a solution and the deadline is approaching, I thought maybe there is someone competent out there who knows how to make a good Fog Of War or who knows a "good" tutorial. Now I know why I never asked questions, because most of the answers are just completely useless, as they don't address the question asked.
     
  8. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    10,468
    I think the problem here is that your question is pretty nebulous and I'm not sure what the answer you want would look like. You never asked for "good" tutorials originally, you asked "how to create a fog of war system" which isn't a simple answer without knowing details of your game and the constraints you have plus your skill level etc.

    I can understand you want something quick by the looks of it but only very specific questions can be answered on forums easily. Maybe someone can search like you have for FOW tutorials but from the sound of it, it'd just be providing you with what you've already got.

    A better approach would be to detail a little more of what you have and how you'd like to implement it etc. Maybe devs can then suggest some technical approaches and/or limitations, alternatives etc.

    Being annoyed at the answers isn't helping anyone though. :(
     
  9. JayTi-JayFiArts

    JayTi-JayFiArts

    Joined:
    Jun 4, 2021
    Posts:
    5
    I need a Fog Of War for a space real time strategy game (example Age of Empires) where the units reveal the area. There should be 2 pieces one where the area is permanently uncovered and one where the area is covered again, the 2nd one should be a bit transparent so you can see the planets underneath. The first one should be completely black.
    I want to use render textures because they seem to be the most performance efficient. However, there is the problem that there is no ground, only an invisible area that catches the raycasts for the unit selection. The whole thing is a 3D game which takes place on one level. Link to Steam: https://store.steampowered.com/app/1982950/Astronomics_Rise_of_a_new_Empire/
    I need a tutorial on how to implement the whole thing, I have already "worked through" various videos but they were mostly quite old or used a projector that does not work because of the missing floor.
     
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,561
    You keep bringing up the importance of a lack of ground. This does not even remotely matter to the problem at hand.

    This is what leads me to believe you simply haven't considered the data flow involved.

    You will need to understand the data before you make any meaningful progress.

    Here's the two parts you will need, at the barest minimum:

    1. a data structure to represent the fog, such as some kind of 2D array of visibility cells:
    --> is each cell binary? either on or off?
    --> Does it have partial reveal, such as once you visit it, then you can see the ground, but none of the units?
    --> this part has NOTHING to do with Unity
    --> units and the game logic will adjust this data structure as the game plays (this part is not necessary to MAKE the fog of war system; you can debug update it by hand to prove it works)

    2. a presentation mechanism to obscure the ground according to the above data structure.
    --> this is the part that will use Unity and whatever mechanism you choose: cameras, geometry, sprites, lights, whatever.

    That's IT. Everything else is a trivial implementation detail.

    Note how NOTHING of the above cares if you have ground, sky, units, water, lava, ice cream, whatever.