- Home /
dynamic node driven room based AI
any place marked with (*) are shaky points, and I would appreciate correction if need be.
Setup: my game is a maze-type game using prefab defined rooms
that are proceduraly placed (a levelManager
will be controlling this). I know that there is a path-node system in Unity, but as far as I can tell it requires baking*, and also contradicts some of my desired functionality (see below). So I have placed Nodes
into my prefabs at desired points (currently Empty GameObjects).
Problem space: I want to have my agents be able to move around the room
that they are created in using the nodes
(wandering), and not be aware of the nodes
in the adjacent rooms
unless told to take a calculated node
path to a target (hunting). then if need be return to their starting room (traveling) via reverse path.
reasoning: because the built in path node system needs baking*, and I want to have the agents only know of a subset of all nodes at any given time (unless given a different subset) I think I will need to roll my own node system.
Question how would I create an extensible node system that can run dynamically?
*what I think it will need is that all nodes
will need to be a node
layer, and that each have a given script. I think that I can have each agent locate local nodes with radius raycasts, but that will not be limited to the given subset unless I am missing something. I thought that I could get around some of this by having the rooms be their own data structure (this thought comes from a C++ OOP mindset), but I don't think that Unity will allow this the same way that I would like as it seems to me that all Objects are aware of everything unless the layers say otherwise, and I don't want to have to have a different layer for each room (mainly because it might not be a fixed number of rooms)
Just as a thought - I use the A* Path Finding Project from the Asset Store - that does not require baking and enables maps to be updated as levels evolve.
@whydoidoit, but that doesn't account for the constraint of limiting agents knowledge to the current room.
So is that really two problems - one is agent navigation in a dynamic environment and the other is selection of potential targets for destinations?
That's how I deal with this - slightly different. $$anonymous$$y characters have memories and use them in their decision making - but I'm treating locations as a list of places that they remember or have been told about. Then when they make a destination decision they only need to call the pathfinding for how to get there. For them they don't care about the physical location of targets or their navigability - because that is ensured (actually they do make some decisions based on distance, but this is cached and available to all of them as a lookup).
So my targeting is straightforward list processing and weighting and my navigation is A*
Answer by Loius · May 31, 2012 at 08:17 PM
When I built a similar solution, I made my Nodes 'intelligent.'
On creation or when moved, a Node compiles and stores a list of adjacent Nodes. If that list has changed since last time, it tells the Path Manager so Paths can update.
When a Room is created, it gets all the Nodes inside itself, then builds a directional Path over those nodes.
Agents request directional Paths (From the Room when wandering, or from the Path Manager when hunting). This way an Agent only knows about its current Path (which translates to only knowing about the room it's in)
The Path Manager does all the heavy lifting of finding paths (and listening for moving nodes and adjusting accordingly); the Agents just happily run along the list of Nodes they're given. Once they reach the end they either loop to the beginning (wander) or do the 'where is Player?!' logic again and either get a new Path or go backwards along the one they have.
@Vicenti I understand what your saying, but I am unsure how to implement it. are there any examples, or tutorials on how to do this. I will have a Level$$anonymous$$anager
that will have all the rooms so do these managers have to exist in parallel, or in composition (then how does one know about the other?),
and how would communication work between them?
Not sure there's any tutorials or anything, it was kindof completely homespun. :)
It should be pretty simple, though, if you object-ify as much as possible.
Agents should know what Room they're in. They can ask Room.Path to get their wander path, which is a link to a path (not an actual path) managed by the path manager (so when nodes move and the paths change, the agent doesn't need to hear about it).
I actually created my room paths manually rather than attempt a programmatic construction (since many of the nodes have line-of-sight to others).
To get a node's adjacent nodes, I just used physics.raycasts with a distance limit to find nearby nodes. Nodes have to be a little off the floor so they can see down inclines.
I think I am understanding, but I am a little lost on the implementation. like how is that my agent considers the nodes in view, but ignores the ones that are occluded by walls?
on top of that I understand what the Path$$anonymous$$anager is supposed to do, but I am a little lost on how to go about it. could I please see even a stripped down commented version of this Path$$anonymous$$anager class/script?