Hi Aron
currently i’m working on a TD game, which user can use an box to block the path,
so every time user try to block the path , i need detect is there remain an open path on the map.
Basically,when the user really put one box on the map , i will create one GameObject attach with GraphUpdate component with it, and modify the tags info.
but for the detect part ,i wonder is there a way that i can set the tag info manually?
here is the code i used right now.
Function:
public GridNode GetAStarNode (int _tileIndexX, int _tileIndexY)
{
GridGraph gridGraph = AstarPath.active.astarData.gridGraph;
return gridGraph.nodes [ _tileIndexY * gridGraph.width + _tileIndexX];
}
public static void SetAttribute (ref uint _target, int _index)
{
if (!HasAttribute (_target, _index)) {
_target |= (uint)(1 << _index);
}
}
public static void RemoveAttribute (ref uint _target, int _index)
{
if (HasAttribute (_target, _index)) {
_target &= ~(uint)(1 << _index);
}
}
Before FindPath:
GridNode node = GetAStarNode (tileIndexX, tileIndexY);
uint tagValue = node.Tag;
SetAttribute (ref tagValue, GlobalConst.TILE_TAG_INDEX_ATTEMPT_BLOCK);
node.Tag = tagValue;
After FindPath:
GridNode node = GetAStarNode (tileIndexX, tileIndexY);
uint tagValue = node.Tag;
RemoveAttribute (ref tagValue, GlobalConst.TILE_TAG_INDEX_ATTEMPT_BLOCK);
node.Tag = tagValue;
Enemy:
each one attach one seeker which can walk on Floor & AttemptBlock Tag;
OpenPathFinder(CESingleton):
attach one seeker only can walk on Floor Tag;
that’s code working most of the time. but when i have dozen enemy on the map , and try to put box on the map quickly, then some enemy can’t find the path
1 each time put one box on the map, all enemy need recalculate the path once.
2 in the game view , there exist one open path (seeker Draw Gizmos can see one green line from begin point to end point)
any idea on why the enemy can’t find path?
PS: Thread Count property i set to None, and this bug only happen when click quickly.
Thanks.