Add weight to path?

Is there a way to make a cell on the grid have an arbitrary extra weight to it? To make a path going through a particular spot have added length?

I’m looking in to using pathfinding for sound propagation; to determine if an enemy hears a noise the player makes. The big issue is that I have doors that will muffle (but not block) noise, so if the path is going through a door it needs to add extra weight/length to that path. If the length becomes too great, the enemy won’t hear it.

As such the added weight needs to be reflected both in calculating the shortest path and also in the total length as calculated by path.GetTotalLength() as that is what I’ll call afterward to determine if the enemy hears it or not.

Ideally this added weight needs to be something I can disable and then reform the grid so the sound isn’t muffled when the door is open, but I suspect this to be the easy part.

I suspect that this feature would also be useful for situations where certain types of terrain slow down someone and should be avoided.

So the main way of adding “weight” to a path would be with a Penalty which you can go about a number of ways such as by marking the door jamb with a GraphUpdateScene object.

But I don’t think that would affect the total length.

I’d suggest using Path.path which would return a list of all the nodes the path takes. You can do a lot here, such as just adding the distance between a node and the next, adding extra for nodes with a penalty.

Okay, but the penalty still adds a numeric value of some kind to the path; is there a way to view that value? Even if it is not a true “length” it still would be the numeric value that I want to use to determine if the enemy hears the sound or not.

I really don’t see how I could reliably find doors within the graph node; I’d have to check each individual node against some other kind of list or detection, and that would be pretty resource intensive.

Hi

The penalty adds a cost to the path. That’s the GraphNode.Penalty value. Connections between nodes normally add a cost of 1000*distance between the nodes. If you use a penalty, then entering a node will additionally add the GraphNode.Penalty as a cost.

You can inspect the total cost of the calculated path using ABPath.cost.

1 Like