I’m trying to make the RichAI agent approach a destination but not to its centre, but rather stop in front of it. What is the best approach for this?
Setting the EndReachedDistance only slows the agent down, it doesn’t stop it.
I tried to stop the agent before it reaches the destination like this:
ai.isStopped = Vector3.Distance(transform.position, target.position) < margin;
but this results in a jittery movement and over reaching as that’s not the actual destination of the agent and it didn’t have time to slow down. Also, this can stop the agent prematurely when navigating around walls.
So I tried to set the destination in front of the target like this:
ai.destination = target.position + (transform.position + target.position).normalized * margin;
This approach has a problem of being imprecise if around walls/obstacles as the direction towards the target from the agent doesn’t have to be the direction the agent actually approaches the target from.
So I tried to first make the agent approach the target normally as
target ai.destination = target.position and when ai.remainingDistance is smaller than margin * 2, I recalculated the destination as
ai.destination = target.position + (transform.position + target.position).normalized * margin;.
But this doesn’t work because remainingDistance seems too imprecise and often returns smaller values than reality.
I tried to trim the path, but that doesn’t work on RichAI because its not using vectorPath. I also tried to use EndingConditions on XPath but that didn’t work with RichAI either. I tried to calculate the path first, get the point on it some margin from the end and send the agent to that point, but the point’s are off for some reason.
What is the best approach to this? I must say, this seems like a very common use case, did I overlook some obvious solution? Because, at this point, I’m thinking of quickly sending an invisible agent first, getting it’s position some margin before the end and then sending the real agent to that position.
Thanks for any help