Download

AI - Chasing Moving Pawn (Character)

I know UE offers some functions like Move To or Move Towards which is sufficient in most cases, But i have special situation in mind:

Let`s take a classic XY coordinate system.

Starting Positions:

Agent A = 0,0
Agent B = 30,30

A will travel along the y-axis and B has the task to catch him. The velocity is for both agents equal ( velocity = 1, ignore additional costs of diagonal movement). Using a naive algorithm will have the following result:

B updates every frame his path to A according the latest position of A, so we see after 5 tick the following positions A = (0,5) and B = (26,25). Later A = (0,15) and B = (3,15) and B will fall behind A, makes a turn and runs then behind A. As both agents have the same speed B will never catch A. This is a scenario which i have seen in many games.

The correct way for B is that he intercepts A (like an average human would do). I know the math but i would like to know if Unreal has already solved the problem and we have somewhere a handy Blueprint function.

I know this doesnt answer your question but I think most people work around this by changing the pursuit speed of the AI even if its just for a short burst. I mean the core problem with what your talking about would be - even if you used a predictive method to find an intercept point for the AI, any player that has half a brain would quickly realize all they need to do is just change their path to run directly away from the AI and it will never catch them. What about just using a tiny cheat - just get the player’s forward vector and add some reasonable amount of units to it and set that as the AI move to point and increase the AI speed slightly. It will look like the AI is predicting where the player is going to run to and will catch the player and doesnt require much effort ?

This is true for open field areas and then A will get away in every situation as the velocity of both agents is equal. But if both agents are restricted by constraints (like a wall in buildings, terrain obstacles or rules (like in Soccer or American Football where players have to stay on the pitch) then the question will be relevant. The last method using a forward vector + something like a velocity factor is the best practical solution. 8 or 10 years ago i have used a mathematical solution based on trigonometry in a XNA app but that creates perhaps too much overhead. By the way the whole scenario is analyzed by Timothy Gay in “The Physics of Football”.

Use a service to calculate at every 0.5s or so, the target position the enemy should go torwards, based on whethever calculations and rules you desire.