- Home /
Is this pathfinding waypoint based AI script viable?
So I am learning programming (so keep an open mind I don't know A* or other complicated algorithms) and building a simple AI follow player script that would allow it to avoid obstacles that don't move. Basically I have a bunch of transform nodes that can reach another node in a straight path so the ai can follow it like an ant trail.
With another script this can be adjusted so that waypoints can automatically and dynamically be created allowing the AI to avoid moving, new, different obstacles during the game. I can write a script that takes every obstacle and create waypoints around or inside depending on tag, etc, and was wondering about performance of doing all this checking only on new, moving, different obstacles every second or frame?
It works by sending a superfast scout following nodes to scout all available nodes and ends at the one closest to the player (leaving a straight path to the player). The nodes will basically use OnTriggerEnter() to add the trail to the AI's path array or remove every node after if it already traverse it, which the AI follows like an ant.
I want to know if OnTriggerEnter() always works even if something zooms through it at lightning speed, (the scout will move super fast since pathfinding needs to be updated for player position). I also want to know the general performance of using multiple scouts for multiple enemies and doing this like every 3 seconds or every node? Is this viable as a pathfinding solution? or should I just use A* and other pathfinding methods?
Super fast object pass trough other objects and also cant trigger event. I wonder why you are even using on trigger enter. Such things should be done as backlogic on data that represents it in efficient manner.
The scout will only follow the nodes so it wouldn't go through objects, but you are saying it doesn't trigger a collider? I am only using on trigger enter to make a very easy to understand script because I am not that good at program$$anonymous$$g yet, and there doesn't seem to exist simple pathfinding scripts.
I must say i am not exactly sure what you are doing. But anyways just to answer your title. Wayspoints are just fine for pathfinding. Even if you were to implement A* you could use them to represent your grid.
If i understand correctly, you send a "scout", scout splits at every crossway, for each node you check the distance from the player, and when you check all nodes it returns closest one?
If this works for you then good. It seems highly unefficial and it doesent return closest path (unless you are also su$$anonymous$$g the travel distance).
To answer your performance question for multiple enemies. It could be a problem doing it like this if your waypoints grow in quantity. Since you are checking every possible root (how are you preventing cycles?) this can become really slow. Doing it once every 3 seconds wont help much either. It could make your game frozen for short period of time. Every three seconds. Usually pathfinding is done over multiple frames.
If i am imagining your algorithm incorectlly, please elaborate.
So it goes sorta like this. Scout(a moving collider) starts at Transform closest to AI object. Transforms are going to be put into arrays for easy traversing in order. It uses Vector3.distance(a,b) to deter$$anonymous$$e distance from player. It stops after finding the Tranform closest to player and sends a Tranform Array to AI object. The transform array is constructed by adding each Transform that the scout collides with, if it collided with the Tranform before, it will delete the indexes after the position of that Tranform in its array. The AI object simply goes towards each Transform in the array, and if close enough to player will simply follow player directly and if path is obstructed, starts the scout again. It does require going through multiple arrays multiple times though to get all this information...
Answer by Tapp · Jan 27, 2013 at 02:17 PM
If I understand you correctly you want your AI to find its way around objects to your Player, a simple way to do this would be to have the Player trigger the nodes (leaving your 'Ant Trail' as you called it) and then have the AI follow this path to the Player, you could use find nearest to allow the AI to find the closest node.
Implementing it properly would need testing obviously.
Your answer
Follow this Question
Related Questions
Why isn't a Ai Waypoint Spawning??? 0 Answers
How can I make AI follow waypoints and choose random ones? 1 Answer
RTS dynamic formation width and length 0 Answers
Sidescroller AI/Pathfinding/Flags/Waypoints 0 Answers
Help with a simple AI 2 Answers