- Home /
Navigation dynamic level generation
I've been working on a project where my game creates a small field of squares on a plane (the squares are technically cubes), each of size 2, 0.1, 2 (xyz) and creates something like a chess game, where each of these squares can have something on it (or not).
The idea is to navigate from a side to another in the field, avoiding anything that can be placed there (it is placed by the player so it must be dynamic).
The real problem is: The normal navmesh resource will just fail to work well with the said dynamic field, so even tagging dynamically created objects as obstacles would not be a solution for my problem, since the field itself is not a obstacle and anything else (other than the field itself) is not supposed to be used by the AI.
I read about a lot of different free solutions for dynamic navigation but it looks like none of them actually gives me what i need, wich is in fact somehow simple: Tag free spots as navigation points and let the ai do its job (i do keep track of what is free and what is being used, so i can actually update the objects state to match the reality of the game, as possible navigation point or not).
Since im somehow new to this thing, i also read a lot of questions like this one but it looks different since im not using a pre-made game terrain and i can be mistaken about tools not being able to do this (the ones i read about at least), if so, please point me out a tool and i can run some tests on it. Also, any further description needed please just ask and i will be happy to provide more information.
Thanks in advance
Answer by Cherno · Oct 10, 2014 at 07:34 AM
Here is how I did it for my Minecraft-like dungeoncrawler, using Granberg's free A* Pathfinding Project:
After creating the mesh for the level itself (floors, walls and such), I re-use the floor mesh generation code to create a mesh for the NavMesh. Each object that can be placed and needs to be impassable hasa Graph Update Object component added to it, and applied upon instantiating. Works flawlessly so far.
I actually did some further reading on the A* project and it looks like it can be done, do you have any code samples or documentation for that specific task?
It all depends on how you build your world. In your case, it sounds like you can just have a GridGraph with one node per tile, and when an obstacle is created, you just call
GetComponent<GraphUpdateScene>().Apply();
on the object (it needs a GraphUpdateScene component, of course). The nodes that are overlapped by the object's GUO boundaries are then flagged as non-walkable.