A* Pathfinding Project

How to recalculate moving target with AI Path?


#1

I’m using the AI Path script to move my AI to the player, but it does not recalculate the path while the player is moving. Adjusting the repath rate doesn’t help, it simply doesn’t recalculate again until the player stops moving.

Any suggestions to have it follow a moving target?


#2

Hey,

The repath rate determines, how frequently it recalculates the current set destination.
You might want to look at your code that sets the destination.


#3

It’s the standard AI Path, AI Destination Setter, and Seeker scripts. I haven’t modified them.

All my code does is enable the AI Path script on awake and disable it on death.


#4

Hey,

Hmm, the default Destination setter does update the destination every frame

void Update () {
	if (target != null && ai != null) ai.destination = target.position;
}

I tested this in the RecastExample scene and it moving the continuously moving the target worked.


#5

I moved the code that enables the AI Path from FixedUpdate() to Update() and it seems to have resolved the issue.

Thanks for your help!