Generating A Hex Map With Fog Of War in Unity

  Рет қаралды 50,463

Game Dev Guide

Game Dev Guide

Жыл бұрын

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 - kzfaq.info?...
• Join the Discord - / discord
• Twitter - / gamedevguideyt
• Facebook - / gamedevguideyt
• Instagram - / gamedevguideyt

Пікірлер: 51
@Merivio
@Merivio 2 күн бұрын
If you want an even cheaper fog-of-war effect, you can use a smoke sprite (doesn't even need to be animated) and have one single particle per tile which you rotate slowly in a random direction. As long as the sprite is over 1.5 times the size of the tile, they'll overlap enough on the grid to look like continuous fog. I did this on a square-grid and the effect looked really good. If you're unhappy with the amount of overlap onto visible tiles you could make the particles smaller but have them at the corners (neighbouring other fog) as well. You can do this with a single particle system too if you manage the particles yourself.
@midniteoilsoftware
@midniteoilsoftware Жыл бұрын
Very cool. I especially like the fog-of-war effect.
@lexibyday9504
@lexibyday9504 5 ай бұрын
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.
@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.
@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! 😂
@PurpleDaemon_
@PurpleDaemon_ Жыл бұрын
For civilization 6 fog of war I highly recommend a guide from LEXDEV. He recreated it just like in the game.
@karue7581
@karue7581 Жыл бұрын
Love your content!
@JohnVanderbeck
@JohnVanderbeck Жыл бұрын
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 !!!
@kantholzwerfer1086
@kantholzwerfer1086 Жыл бұрын
Cool but it would be nice if you showed the whole scripts or attach them somewhere to download
@relativityftw9097
@relativityftw9097 3 ай бұрын
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.
@velociraptor5962
@velociraptor5962 Ай бұрын
In the previius video he said it was on patreon
@relativityftw9097
@relativityftw9097 Ай бұрын
@@velociraptor5962 Not very useful when google leads straight to this video. Am I supposed to mind read which video holds which references at minute X, second Y? Damn xD
@HurriO4
@HurriO4 Жыл бұрын
8:55 "I'll only gloss over the basics of A* pathfinding" *proceeds to walk through the entire process step by step*
@GameDevGuide
@GameDevGuide Жыл бұрын
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!
@timowen8990
@timowen8990 Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
​@@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(); } } }
@myk3l9675
@myk3l9675 10 ай бұрын
How would you outline a collection of tiles like the city influence borders in civilization?
@SychMedia
@SychMedia Жыл бұрын
Why I can't see this video in a list of channel
@xkittencatx
@xkittencatx Жыл бұрын
We miss you :3
@hxlxna_9962
@hxlxna_9962 Жыл бұрын
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
@JM-dc5rn
@JM-dc5rn 9 ай бұрын
This implementation seems like it would hit perfomance hard.
@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.
@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.
@micca971
@micca971 Жыл бұрын
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.?
@mehmedcavas3069
@mehmedcavas3069 Жыл бұрын
would the fog particle use less processing power if you would create a single fog mesh via code?
@GameDevGuide
@GameDevGuide Жыл бұрын
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.
@rokuro6517
@rokuro6517 Жыл бұрын
Hi guys, i have issue at 4:20 , idk how to setup the generator settings :(
@alexandraclaretguarenas5176
@alexandraclaretguarenas5176 Жыл бұрын
Muchas gracias no hablo ingles pero gracias a ti podre hacer mi juego de estrategia :)
@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.
@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);
@iangraham6730
@iangraham6730 11 ай бұрын
I found this very very hard to follow along to. The first grid video wasn't as bad to follow.
@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
@Cc-my5yh
@Cc-my5yh Жыл бұрын
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 Жыл бұрын
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 Жыл бұрын
​@@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 Жыл бұрын
@@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()
@youraveragedude8767
@youraveragedude8767 Жыл бұрын
Are you still working on the ViewGraph vid mate? You said you’re going to do one…
@GameDevGuide
@GameDevGuide Жыл бұрын
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! 🙏
@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 5 ай бұрын
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
11 Things You (Probably) Didn't Know You Could Do In Unity
13:49
Game Dev Guide
Рет қаралды 150 М.
Pathfinding - Understanding A* (A star)
12:52
Tarodev
Рет қаралды 120 М.
Who has won ?? 😀 #shortvideo #lizzyisaeva
00:24
Lizzy Isaeva
Рет қаралды 65 МЛН
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 8 МЛН
A clash of kindness and indifference #shorts
00:17
Fabiosa Best Lifehacks
Рет қаралды 118 МЛН
Building a Camera Controller for a Strategy Game
17:48
Game Dev Guide
Рет қаралды 192 М.
Procedurally Generating A Hexagon Grid in Unity
11:29
Game Dev Guide
Рет қаралды 115 М.
How to Create a Hexmap from Scratch
8:08
The Dice Society
Рет қаралды 4,4 М.
Giving Personality to Procedural Animations using Math
15:30
t3ssel8r
Рет қаралды 2,5 МЛН
How I Learned Procedural Generation
5:36
Lejynn
Рет қаралды 256 М.
Unlocking The Power Of Unity's Scriptable Render Pipeline
21:05
Game Dev Guide
Рет қаралды 197 М.
How to Program in Unity: Observer Pattern Explained
15:57
iHeartGameDev
Рет қаралды 110 М.
10 Things You NEED to Be Doing in Unity
11:40
Tarodev
Рет қаралды 128 М.
Who has won ?? 😀 #shortvideo #lizzyisaeva
00:24
Lizzy Isaeva
Рет қаралды 65 МЛН