Hey! We’ve been using this for a few months on our project, but we’ve just added a new feature and I’m busting my skull trying to work out how to get this A* package working right for it.
We have a simple top-down 2D game where a character walks around the screen (this was the easy part).
So here’s the problem:
The player is not allowed to pathfind to areas they cannot see. In the above image, the player would not be able to click the lower lit area, because there is no valid path between those areas.
In the image below, they can pathfind because there is a third light connecting the two areas.
The solution I had in mind was to use a mask layer, where colliders with the “Light” layer would be traversable as normal and non-lit areas would be traversable, but I can’t find an option for this anywhere.
You can instead add a layer “NonLit” which you add to the “Obstacles” mask, when an object is lit by a light, you place it in another layer and recalculate the graph around it.
This is relatively slow though. A faster solution is to modify the Path class slightly to mark the CanTraverse method as virtual, then you create your own path class inheriting from ABPath which overrides it and does a check like “is this node close enough to a ligh”.
Thats really great advice, thanks! I’ve gone for the second solution - am I right in thinking I’ll need to modify Seeker and change the reference to Path to CustomABPath? I’m finding that my override never gets called.
Instead of calling seeker.StartPath (startPoint, endPoint)
you can construct a path manually using CustomABPath path = CustomABPath.Construct (); (you will need to write this method, look at the one for ABPath, you can basically just copy and paste it)
and then use seeker.StartPath (path);