I have an object that is set to move to a point using AIDestinationSetter.target. I understand that pathfinding still occurs even after we reach the destination, and I think this is what my problem is.
Once I have detected that the object is at the destination, I rotate the object to look at the target (for example, an employee walks to a shelf and then turns to face the shelf so they can “stock it”).
When this happens, the object seems to move again and spin around. My theory is that the rotating is nudging the object off of the node, and then the pathfinding kicks in and tries to get back to the node, which causes the object to spin around as well.
If I set “canMove” to false manually in the inspector, they do not do this. This doesn’t really work in script and I rather not toggle canMove on and off to get around this since that could make a mess elsewhere in the code.
I also tried setting AIDestinationSetter.target to null once it’s reached it’s path but the object still seems to want to pathfind to the node it stopped at.
I believe this is a similar issue to this one way back in 2013. I’m not really sure what his solution was though, I think the code might have changed since then.
It may also be similar to this unresolved post as well:
Here is my rotation code. I tried a bunch of different rotation methods to try and rule this out. The all result in the same thing. This is placed in a coroutine that stops when the angle between the target and the object gets low enough, but here’s the meat of it, nothing fancy:
dir = (target.position - transform.position).normalized; dir.y = 0; //so we don't tilt up or down rotTo = Quaternion.LookRotation(dir); transform.rotation = Quaternion.RotateTowards( transform.rotation, rotTo, Time.deltaTime * turnSpeed);
Thank you in advance.