Generating A Hex Map With Fog Of War in Unity

แชร์
ฝัง
  • เผยแพร่เมื่อ 13 ธ.ค. 2022
  • Procedural Generation of a Hex Map, Hex Based Pathfinding, and revealing the map via Fog Of War are three key mechanics of any great strategy game. Let's take a look at how we can use Unity to procedurally generate a hex map and have a character explore it!
    🎨 Check out Outstandly and consider working with them to get great-looking art on your next project - outstandly.agency/gamedevguide
    Hex Grids Video - • Procedurally Generatin...
    Selectable/Outline Shader - • Creating an Outline Ef...
    More Info On Hexes - www.redblobgames.com/grids/he...
    A* Playlist From Sebastian Lague - • A* Pathfinding (E01: a...
    --------------------------------------------------------------------------------
    Want to support the channel?
    ▶️ Help fund new episodes by joining the Patreon - / gamedevguide
    💡 Get One-Month Free of Skillshare Premium - skl.sh/MKR826
    Use these links to grab some cool assets from the asset store:
    Get the Must Have Assets! - assetstore.unity.com/top-asse...
    Free Unity Assets! - assetstore.unity.com/top-asse...
    New on the Asset Store! - assetstore.unity.com/top-asse...
    Top Paid Asset Store Packages - assetstore.unity.com/top-asse...
    Asset Store Partners - assetstore.unity.com/lists/as...
    --------------------------------------------------------------------------------
    Socials and Other Stuff:
    • Subscribe - th-cam.com/users/gamedevguide?...
    • Join the Discord - / discord
    • Twitter - / gamedevguideyt
    • Facebook - / gamedevguideyt
    • Instagram - / gamedevguideyt

ความคิดเห็น • 48

  • @lexibyday9504
    @lexibyday9504 4 หลายเดือนก่อน +2

    Watching this is making me want to see a multiplayer RPG built from this starting point. You explore the world on this screen then get a pop up window of the "dungeon" you've found yourself in and you can explore that on everyone else's turns. Turn based games can involve a lot of waiting so I think it's god to give players something to do while they wait, especially if the other players are just competing with you rather than actively fighting against you. If you don't have anything to do on your turn the game will progress everyhting you're waiting for in the background without interupting your dungeon crawl. When there Finally is something to do, you'll get a message that something needs your atention and the dungeon window will hide itself. As soon as that's dealt with, the window reopens. Turns in the dungeon are seperate to turns on the map but, when multiple players are in the same dungeon, they'll naturally be in the same turn counter. If everyone was in the same dungeon the turn counters might match up because no one in needed on the world map. Now I really want to make this with someone.

  • @midniteoilsoftware
    @midniteoilsoftware ปีที่แล้ว +2

    Very cool. I especially like the fog-of-war effect.

  • @AnEmortalKid
    @AnEmortalKid ปีที่แล้ว

    As someone who recently implemented fog of war, I could have used this 2 weeks ago. That culling mask trick with the camera is great.

  • @kantholzwerfer1086
    @kantholzwerfer1086 ปีที่แล้ว +19

    Cool but it would be nice if you showed the whole scripts or attach them somewhere to download

    • @relativityftw9097
      @relativityftw9097 หลายเดือนก่อน +1

      Aaaaaand here we are 1 year later, and there is still zero info on methods used in detail, its just a pure "hey guys look, I can do this thing!"-video. Incredibly annoying.

  • @PurpleDaemon_
    @PurpleDaemon_ ปีที่แล้ว +8

    For civilization 6 fog of war I highly recommend a guide from LEXDEV. He recreated it just like in the game.

  • @HurriO4
    @HurriO4 ปีที่แล้ว +4

    8:55 "I'll only gloss over the basics of A* pathfinding" *proceeds to walk through the entire process step by step*

    • @GameDevGuide
      @GameDevGuide  ปีที่แล้ว +1

      Haha I meant that I wouldn't go into specifics about how it works, as it's covered in detail in so many other places, but figured the code was still valuable to the topic!

  • @MatthewCaldwell
    @MatthewCaldwell ปีที่แล้ว

    DUDE! I was literally thinking about hex maps yesterday and planning on working on it today.

    • @GameDevGuide
      @GameDevGuide  ปีที่แล้ว

      Hopefully you've found the video helpful then! 😂

  • @karue7581
    @karue7581 ปีที่แล้ว

    Love your content!

  • @JohnVanderbeck
    @JohnVanderbeck ปีที่แล้ว +10

    Currently working on a very challenging project where I have an Icosphere built out of mostly hexagons (with a few pentagons because geometry) which looks and works great but referencing and addressing the connections between hexes is a real challenge!

    • @umbrason.
      @umbrason. ปีที่แล้ว

      What exactly are you struggling with? You could just treat your tiles like a graph with nodes and edges (just like a navMesh).

  • @RenCode
    @RenCode ปีที่แล้ว

    Much appreciated !!!

  • @SychMedia
    @SychMedia ปีที่แล้ว +3

    Why I can't see this video in a list of channel

  • @myk3l9675
    @myk3l9675 8 หลายเดือนก่อน +1

    How would you outline a collection of tiles like the city influence borders in civilization?

  • @timowen8990
    @timowen8990 ปีที่แล้ว +4

    Really good information here, I love hex tile based games. I do have a question though, at 4:27 you show [EditorButton("Layout")] I have searched the Unity API attributes and have not found this

    • @halimebeyzacicek8440
      @halimebeyzacicek8440 11 หลายเดือนก่อน

      Me too.
      how can i solve this "Assets\_Game\Scripts\2\HexGrid.cs(31,6): error CS0246: The type or namespace name 'EditorButton' could not be found (are you missing a using directive or an assembly reference?)"?

    • @damienshepard6075
      @damienshepard6075 11 หลายเดือนก่อน +3

      ​@@halimebeyzacicek8440 It's a custom "InspectorGUI" you need to create one with a public class Editor and a UnityEditor library. You have a choice, with new script, or in existing HexGrid script (out of "monobehaviour" class brackets)
      like this :
      [CustomEditor(typeof(HexGrid))]
      public class customInspectorGUI : Editor
      {
      public override void OnInspectorGUI() {
      DrawDefaultInspector();
      HexGrid hgrid = (HexGrid)target;
      if(GUILayout.Button("Layout")) {
      hgrid.LayoutGrid();
      }
      }
      }

  • @micca971
    @micca971 ปีที่แล้ว +3

    11:21 why dont you show it all? what is currentPath, what is nextTile, where do I declare them, how do I pass them to the controller, etc.?

  • @JM-dc5rn
    @JM-dc5rn 7 หลายเดือนก่อน

    This implementation seems like it would hit perfomance hard.

  • @hxlxna_9962
    @hxlxna_9962 ปีที่แล้ว +7

    i like your content but it's really hard to follow especially if you use extensions or jump from script to script. Please tell us where you attach your scripts and what extensions you use in your next videos

  • @gower1973
    @gower1973 ปีที่แล้ว

    I think it would look better if the fog was partially transparent next to revealed terrain so you’ve got some falloff and not a hard revealed not revealed.

  • @iangraham6730
    @iangraham6730 9 หลายเดือนก่อน +3

    I found this very very hard to follow along to. The first grid video wasn't as bad to follow.

  • @xkittencatx
    @xkittencatx ปีที่แล้ว

    We miss you :3

  • @mehmedcavas3069
    @mehmedcavas3069 ปีที่แล้ว

    would the fog particle use less processing power if you would create a single fog mesh via code?

    • @GameDevGuide
      @GameDevGuide  ปีที่แล้ว +1

      Possibly! There's definitely a lot of potential to play around and optimise. The new Render Pipelines also have VFX Graph which have Particles rendering on the GPU instead of the CPU, so could be much much more performant out of the box.

  • @alexandraclaretguarenas5176
    @alexandraclaretguarenas5176 ปีที่แล้ว

    Muchas gracias no hablo ingles pero gracias a ti podre hacer mi juego de estrategia :)

  • @Xhanatos
    @Xhanatos ปีที่แล้ว

    How could you do it, that when you leave visited Hex, they become partly foggy again if not in vision of any character.

  • @PurpleDaemon_
    @PurpleDaemon_ ปีที่แล้ว

    Do someone know how the gradient area outline made? Like on 0:24.
    I implemented this by painting the vertices on the edge of the geometry, then using that in the shader. But the solution does not seem to be the most optimal.

    • @artemartem1235
      @artemartem1235 ปีที่แล้ว

      You need to add a layer to your shader which will only have non zero alpha near the edges. You can watch brackeys tutorial on a force field shader and take a part where a field is interracting with other objects on it's way. Or look for any tutorial of water shader where they are doing water foam. Than by combining parts of those shaders you would get the effect you need. I am not that good at shaders to name the concrete nodes.

    • @PurpleDaemon_
      @PurpleDaemon_ ปีที่แล้ว

      @@artemartem1235 How do you understand in the shader what is and edge and waht is not? I researched those tutorials, but there the essence is in intersection with objects, it's a little different. Now I'm exploring the possibilities of signed distance fields.

  • @rokuro6517
    @rokuro6517 ปีที่แล้ว

    Hi guys, i have issue at 4:20 , idk how to setup the generator settings :(

  • @nathanwakefield1081
    @nathanwakefield1081 ปีที่แล้ว

    On the raycasting: both this video and the Outline PostProcess video use `InputEvents.current.mousePosition`, but I don't see where `InputEvents` is setup or is defined. Can anyone assist?

    • @conrad1870
      @conrad1870 ปีที่แล้ว

      It is an extension he uses. This code worked for me:
      Vector3 mousePosition = Input.mousePosition;
      mousePosition.z = Camera.main.transform.position.z;
      Ray ray = Camera.main.ScreenPointToRay(mousePosition);

  • @prasantabhattacharya7495
    @prasantabhattacharya7495 ปีที่แล้ว

    At 10:30 nodesNotEvaluated has only 1 element that we assign in the top as origin, then the for loop i set to start from int = 1, that means its skips the first one, and thats resulting in infinite while loop and crashing my system. It never finds a path, it keeps checking the same 1 node and than also skips it.... Also my Node base is showing as null

    • @MrCakeZombie
      @MrCakeZombie ปีที่แล้ว

      did you ever find the solution to this? I am also getting an infinite loop

    • @MrCakeZombie
      @MrCakeZombie ปีที่แล้ว

      You wouldnt so happen to have your Node class extending monobehaviour would you? I found out the reason why my unity was stalling is because my Node class was extending monobehaviour and that why it seemed that there was an infinite loop. Otherwise, I just followed along with the video and everything seems to work fine

  • @youraveragedude8767
    @youraveragedude8767 ปีที่แล้ว

    Are you still working on the ViewGraph vid mate? You said you’re going to do one…

    • @GameDevGuide
      @GameDevGuide  ปีที่แล้ว +1

      It's definitely still a video I want to make, I'm just trying to figure out the angle of approach to make the video as informative and as interesting as possible, whilst also feasible to actually produce 😂 - it's a big topic so I'd want to make sure I can do it justice

    • @youraveragedude8767
      @youraveragedude8767 ปีที่แล้ว

      @@GameDevGuide Honestly… You’re truly in the right! ViewGraph has to be a HUUGGEE API and you taking your time with it will definitely make the quality better! I thank you for your dedication! 🙏

  • @Cc-my5yh
    @Cc-my5yh ปีที่แล้ว +2

    Love the video, gave me some good ideas for a few projects :) I wanted to ask for some clarification on around 4:49 GetComponentInChildren().mesh will return a null reference, since transform.AddChild(tile) has not yet executed, so there would not be any children for the HexTile GameObject. At least this is what I understand is happening. Also where could I find more information regarding transform.AddChild(x), can't find a reference to it in the Unity documentation. Thanks in advance for the help :) Look forward to your next video.

    • @GameDevGuide
      @GameDevGuide  ปีที่แล้ว +1

      It's an extension method I use. Just a shorthand for transform.setParent

    • @Cc-my5yh
      @Cc-my5yh ปีที่แล้ว

      @@GameDevGuide Thanks for the fast reply ❤

    • @androsynth976
      @androsynth976 ปีที่แล้ว +2

      ​@@GameDevGuide I'm getting a null reference exception on the line with collider.sharedMesh = GetComponentInChildren().mesh;
      The error says: NullReferenceException: Object reference not set to an instance of an object
      HexTile.AddTile() at HexTile.cs:28
      AddChild doesn't exist, and I see you are using it as an extension. I don't see it in the video, so I put it as transform.SetParent(tile.transform); but that doesn't work either. What am I missing?
      I also had to install an extension for EditorButton, because before it did not exist.

    • @Cc-my5yh
      @Cc-my5yh ปีที่แล้ว +2

      @@androsynth976 In HexTile.cs AddTile() change the Tile = GameObject.Instantiate(Settings.GetTile(TileType)); to Tile = GameObject.Instantiate(Settings.GetTile(TileType), transform); this will add the tile model to the hex tile game object that was created. This should fix the null reference error since GetComponentInChildren needs to have the model as a child to find the mesh, which was not shown in the video since he used AddChild()

  • @laniakeadev.2271
    @laniakeadev.2271 ปีที่แล้ว

    Oh I'm on a wrong wat :( I'm developing a a hex-based game (Early Access) in 2D, and since the beginning had choice a 2D sprite map without mesh generation and did building and other things over it.

  • @jasic1970
    @jasic1970 4 หลายเดือนก่อน

    This is Pretty nice, but i don't think that having this many Single Meshes is a good idea. You also cannot have ramps or anything like that the way you are doing it. There could also be some problems with performance having this many single Meshes.
    What is your take on my concerns ?
    have a nice day