Support Forum

Reset remaining distance?

Hi there,

I have an AI that chases me, once I get too close to it. When it’s chasing, I have an if statement going:

        if (ai.remainingDistance <= attackRadius)

This makes it attack, once it gets close enough. It works like a charm on the first go- However! If I get far enough away and it stops chasing me, once I go near enough again, this instantly fires the AttackFunction(), as if it was close enough. When I do a Debug.Log(ai.remainingDistance), I realise the distance is not reset, when I get far enough away.

Currently, when I get a certain distance to the AI, I run this:

                ai.isStopped = true;

But that doesn’t seem to reset the remaining distance.

Any idea how to do this?


Hmm. That seems odd. Looking at the code the remaining distance should be reset to infinity whenever SetPath(null) is called. Are you sure you don’t let it calculate more paths after this (maybe you also want ai.canSearch = false)