0
\$\begingroup\$

I have a server with a NavMesh component that moves a bunch of NavMeshAgents in the scene and I want to sync their movement to connected clients. I'm expecting a huge amount of AI controlled characters, so I want a way that requires as few updates as possible.

Here's my initial approach: I separated linear velocity and angular velocity. When the velocity changes (I set up a threshold so that it only syncs when the change is significant), I send an update to clients so they update their velocity, then they calculate their new position based on the last synced velocity in their update function. I do the same thing for angular velocity and I update the character's rotation in the update function.

I was also planning to send a full sync of the character's position + rotation at a certain time interval to correct any major errors in movement.

It works okay for the linear velocity, but the rotation is not precise enough, so the character gets out of sync very quickly.

Do you have ideas on other approaches I could try? Or ways to improve my current approach?

We're not using Unity high level networking, we're building from the Unity Network Transport.

\$\endgroup\$
  • \$\begingroup\$ Have you tried just sending regular position & direction data to the clients, and get the clients to interpolate for a smooth update? \$\endgroup\$ – Steve Smith Jan 2 at 14:12
  • \$\begingroup\$ I haven't, because I thought I would need to send too many updates considering there might be a lot of characters. But maybe if I don't send many updates and interpolate it would be okay, I'll have to try. Thank you! \$\endgroup\$ – Jonathan Parent Jan 2 at 22:04
0
\$\begingroup\$

This is a prediction problem, 1st order dead reconning (velocity and position/orientation) is not ideal for AIs.

I would simulate AI's on all clients, and periodically send corrections (velocity position/orientation). This is very similar to what you have tried, but the difference is that the prediction should be much more accurate. To smooth things out, you could interpolate the corrections between sends, but to start with, try direct updates to see how it works.

\$\endgroup\$
  • \$\begingroup\$ I wouldn't be able to simulate the whole AI process, because it relies on information that isn't available on the clients, but I could send their current target destination and try predicting movement, and complement that with position/orientation update with interpolation for a smooth movement. That gives me much to experiment with, thanks for the ideas :) \$\endgroup\$ – Jonathan Parent Jan 2 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.