Hello Unity Forums! ![]()
I have created a very simple node-based pathfinding script using the A* algorithm (or more specifically, a version of the pseudo-code found on wikipedia :)). It uses nodes placed within the scene (at every corner), which have a node script attached. This node script has data on that particular node, such as linked nodes and availability. It finds a path (currently its not the shortest path, but I think I know the heuristic that will find the shortest), but the path currently has to start and end at a node.
I plan for it to be used for the character AI. Unfortunately, since the game is not based on a grid system, the characters are not going to always be on a node or moving to a node (eg. enemies may see the player and stray off the path to attack). Therefore, I do not know the nodes that are nearby the character, nor do I know the nodes that are nearby the target.
I thought perhaps to make these “dynamic” nodes, which, every so often (perhaps one raycast per frame, or all the raycasts every second), cast a ray to every node in the scene to check whether they can be linked. Then I have a dynamic node for the character and the target, that find all the neighboring nodes, so that it can find the path.
I believe this can work, but my question is: Is there a better (more efficient) method of doing this? In my scenes, there may be hundreds of nodes. If I cast a ray for every one of those nodes, per character, I would think that would be very cpu intensive. I’m not asking this on UA because there may be many answers to this and probably some personal preference. Also UF is better for conversation.
If your wondering why I’m not using a pre-made pathfinding system on the asset store, it’s because most are in C# and are appear to be overly complicated.Although I can read C# well, I don’t really feel like going in and putting in some touches in a program that I do not completely understand (especially in this case). Also, I don’t like the interface ;).
Thanks for reading and for all responses and comments! ![]()