Need help implementing a system that puts penalties on nodes that are not in cover

I’m trying to implement a system where the AI can dynamically find paths the have cover along the way. Here’s the rough overview of how I’d like to do it.

  1. Generate a list of points/vector3’s that correspond to and are linked to all of the nodes on a grid graph.
  2. From each of those points fire a raycast from directly above the point (to match the height of the AI) towards the player to determine whether or not the position is “in cover” (this would be done continually so that the points are always up to date)
  3. For every point that is not in cover, the corresponding node is given a penalty.

I’m not sure how to the penalty system works or even how to assign penalties to specific nodes, so that is my first problem. Second, I’m not sure how to best create a list of points that is linked to all the nodes (not even sure how to find the list of all nodes).

There’s couple other things that I’d like to do that may complicate things. First, I’d like to keep the system as dynamic as possible. I want enemies to prioritize paths in cover differently depending on their state (for example, an enemy with low health would avoid non covered nodes more than a full health enemy). I’d also like to be able to access the list of neighbors for each node in order to find nodes that are in cover but have neighbors that are not (this is useful as it can provide positions for the ai that allow it to pop in and out of cover)

I suppose my main questions are:

How can I access a list of all the nodes (and get information such as position and neighbors)?
How do access/change the penalties for each node?
How can I dynamically adjust how expensive penalties are based on AI state?

And perhaps most importantly:

Is this even a reasonable way to go about doing this, or is there a faster/easier way?

Hey,

To loop through all the nodes on the graph you can follow the documentation here: https://arongranberg.com/astar/docs/accessing-data.php
Doing this for the grid graph or layered grid graph is most logical of course.

From here you can get all the data you’d need. Such as position, and neighbouring nodes. But also modify the tags. You can create a class based on the graph Modifier, to have an easy to use pre-made event system:
https://arongranberg.com/astar/docs/class_pathfinding_1_1_graph_modifier.php

Hope that helps

1 Like

Very helpful! Thank you!

What would be the purpose in making a class based on the graph modifier? Is it just so I can make it get/update the node data whenever a graph scan is completed? Also what “tags” are you referring to? I imagine this is stuff that is in the documentation, but I’m having trouble finding it.

Indeed the graph Modifier is a base class that calls events during the scan and post scan.

Tags are a penalty system is there to modify the path calculation, this can be altered per agent.
Read more about the the tags here: https://arongranberg.com/astar/docs/tags.php

Just what I needed! Thanks!

2 Likes

Sorry for the late answer. I am currently traveling and I lost my laptop on a flight, so I haven’t been able to work for a while.

As an addition to what @ToastyStoemp said. The ITraversalProvider interface is very handy if your penalties are dynamic and change per agent and very often. It can be cheaper than updating the graph all the time. https://arongranberg.com/astar/docs/turnbased.html#ITraversalProvider