I have been playing with methods of moving my AI in a multiplayer environment. I am not using Behavior trees as I prefer to handle it with blueprints. The current scenario I am working with involves fleeing from the player. I am able to obtain a target location vector that the AI should move to. So far I have implemented two methods.
- Using a loop, execute “Add Movement” nodes on the AI by calculating the vector based on the current location and target.
- Use a “AI Move To” node, passing the target vector directly.
The first method works nicely with the animations as the controlled pawn will rotate towards the movement vector smoothly. I can also update the target vector at any time and the pawn will rotate to the new target smoothly. However, this does not work for actual pathfinding; the AI will move directly towards a vector, regardless if the path is blocked. It will run against an obstacle endlessly if it’s in the way.
The second method allows for the pathfinding to move the AI along a nice path to get to the point. The problem is if I need to update this point, there is a distinct stuttering in the movement as the pawn stops the previous AI Move To task and starts a new one.
I wish to code my own AI Move To. In order to do this, I need to obtain the pathing data that AI Move To uses. I’m assuming it’s an array of vectors but I’m not sure. My pseudocode for this would be
Get pathing_data
Set final_location equal to pathing_data[pathing_data.last_index] (last element in array)
Loop - for each node in pathing_data
Set next_node_location equal to pathing_data[current_index]
Loop - While pawn is not close enough to next_node_location (vector length of current location minus next_node_location < 25 or some minimum threshold)
Add movement input towards next_node_location (current location minus next_node_location fed into “Add Movement Input” as world direction)
The process would need to be interruptable so that I can re-start the process with new pathing_data if needed.
Also, I suppose I will need to continually check if the path is valid (unobstructed) with each iteration of the loop. If the path becomes blocked, it will need to re-calculate the nodes from the current location to the target location.
Finally, I will probably need to calculate the total length of the path when re-calculated. If there’s a scenario where the AI is attempting to walk 100 units through a doorway and the door becomes closed, I don’t want it to use a path where it would walk 1000 units around the back of the building, through the back door and to the other side of the front door.
Anyway, I think I’ve been rambling on enough. Is it possible to obtain the raw pathing data used by “Move To” nodes?
Edit: After some wading through lots of posts about behavior trees, I may have found a post to give me the answer I’m looking for (https://answers.unrealengine.com/questions/590829/get-pathfinding-points.html). However, I’d still be interested in hearing others’ thoughts on this if anyone had suggestions for different ways to accomplish this.