- A* version: 5.0.6
- Unity version: 2022.3.49f1
I’m working on a custom pathfinding function in Unity using the A* Pathfinding Project. My current implementation calculates a path between a start and end position, but it’s not considering tags or penalties as intended. It’s does calculate the path. Here’s my current code:
public void CalculatePath(Vector3 start, Vector3 dest, OnPathDelegate onPathCompleteDistance, AIGraphMask aIGraphMask, bool blockUntilCalculated = false, bool pushToFront = false)
{
NNInfo nearestNodeInfo = AstarPath.active.GetNearest(dest);
// Check if the node is walkable
if (nearestNodeInfo.node != null && nearestNodeInfo.node.Walkable)
{
var path = ABPath.Construct(start, dest, onPathCompleteDistance);
// Set the graph mask if specified
path.nnConstraint.graphMask = AStarPathfinding.GetGraphMask(aIGraphMask);
path.nnConstraint.tags = (1 << 0);
path.nnConstraint.constrainWalkability = true;
path.nnConstraint.constrainArea = true;
path.nnConstraint.constrainTags = true;
path.nnConstraint.constrainDistance = true;
AstarPath.StartPath(path, pushToFront);
if (blockUntilCalculated)
{
path.BlockUntilCalculated();
}
}
}
I have a few specific questions:
- Why isn’t my function considering tags even though I’ve set
path.nnConstraint.tags = (1 << 0)
andpath.nnConstraint.constrainTags = true
? - How can I modify this function to take penalties into account when calculating the path?
- Are there any other improvements or best practices I should consider for this pathfinding implementation?
Any help or guidance would be greatly appreciated. Thanks!