Evaluating a Seeker's traversable tags against a node tag

Hi there! I need to be able to check whether a particular node’s tag is set to traversable in a Seeker’s tagMask. Is there a tidy way to do that? I searched the forum and couldn’t find anything.

I have an AI that samples potential destination nodes, scores them based on contextual factors, and caches them for its next move decision. It should exclude destination nodes that the seeker can’t actually traverse. I had been using node.Walkable for this, but now I have agents that are constrained by different tag masks.

Something like this fake helper method is what I’m after:
if (seeker.canTraverseTag(node.Tag))

If there’s some fancy bitmask math to do, I’ll do it, I’m just not sure exactly how. I’ve set bits in the tagMask before, but I’m not sure if comparing individual bits works in a similar way.

Appreciate any help, thanks!

Ok, so I’m doing some more reading about bitmasks and I’m wondering, do I just need something like this to check the bit is set?

if (seeker.traversableTags & (1 << node.Tag) != 0)

Ok, so I got this working. In case anyone stumbles across it later, I wrote an extension method for the seeker:

        /// <summary>
        /// Checks if a Seeker's tag settings allow traversal of an Astar GraphNode, based on that GraphNode's current tag.
        /// </summary>
        /// <param name="seeker"></param>
        /// <param name="graphNode">The graphNode being checked for traversing.</param>
        /// <returns>Returns true if the node can be traversed.</returns>
        public static bool CanTraverseTag(this Seeker seeker, GraphNode graphNode)
        {
            return (seeker.traversableTags & (1 << (int)graphNode.Tag)) != 0;
        }
2 Likes