Why Humanoid.MoveToFinished is so slow?

I am working on a pathfinding AI agent. It is already finding the right paths and it manages to traverse each waypoint.

The issue is that my agent starts to stutter between each waypoint after about 10 to 30 seconds. This is caused by the Humanoid.MoveToFinished event.

I am aware that this is a known issue, but I would like to understand why this happens. As a developer, I want the Humanoid.MoveToFinished event to work consistently. Of course, I could detect if the waypoint is reached myself, but I want to understand why the event I used is so slow. Is this a bug?

There is another thread on this issue, but I would like to use the event if that is possible.

2 Likes

not really sure why it ends up lagging, could be due to a memory leak but i didn’t test it and i’m honestly just guessing, it also could be running the new deferred event system, so the event may be getting called on the next runtime cycle or whatever it’s called, don’t remember. at the time i was very inexperienced at developing so i’m sure i didn’t properly test it. magnitude is very efficient though, when comparing just 2 positions though so it’s not that big of a deal to loop it w/ wait() you could easily run hundreds of magnitude comparison loops if not thousands before any lag hit. obviously the pathfinding itself is very expensive though.

My current workaround is to use the Humanoid:Move method to move towards the direction of the next waypoint from the current waypoint. This works even if the agent is stuttering.

I am starting to think that this might be a network ownership problem? I have a modified copy of the place in the video example.

StutteringMoveTo.rbxl (122.4 KB)

Ok, so this stuttering issue is caused by automatic network ownership… Basically, what happens is that whenever you get too close to the agent, it will set your player as the network owner of the agent. This is not logical, since the agent is controlled from the server. So essentially, the server is telling it to move to a waypoint, while the server is not in sync with the network owner (that is supposed to be the server itself)… Already confused yet?

In the video, you can see that when I get too close, I become the network owner. And when I leave the agent’s proximity, the network owner becomes nil (the server). This shift in network ownership causes the agent to noticably stutter.

6 Likes