- Home /
Animation with root motion synchronization in multiplayer
Short version: How can be animations with root motion synchronized in multiplayer (or networking in general) so the animations are fluent and synchronized as much as possible?
Long version: Movement of characters in my project is controlled by root motion of animation, so my code calculate speed and angular speed from user input: user clicks on scene, NavMeshAgent calculates path and result is used to navigate the character. Each player has it's own character and I want to synchronize their movement using networking.
It's not authoritative server networking: each client is responsible for moving their character.
When a character receives new destination from user, first few corners from the path are sent to other players - when first destination is reached, next corner is sent, so all players keeps track of character's path.
Each client calculates movement of the character from the path and animate it accordingly.
When the character is too long away from expected position (expected = on it's "home" client), it's moved there and rotated accordingly.
But this is not working well:
According question 589291 animations are calculated in Update() and not FixedUpdate() (and then interpolated) which causes following:
When fps on clients is different, character makes different stepd and turnd on corners which makes animation different and their movement too. It's all out of sync.
In other words, unlike physics, animation movement (root motion) is apparently not predictable.
So my question is: is there a way to prevent this, or root motion is unusable for multiplayer (making it singleplayer-only feature)?
Notes:
From my description it should be clear I use movement prediction. Reason is simple: when I "just" synchronized animation and position, it was everything but fluent, especially in corners where speed and angular speed is changed in much bigger rate then 15 updates per seconds which is default update rate for networking. Of course I could change the rate, but I need to think about bad quality connection (which is not my whim, but I cannot write more).
Everything is tested on single PC so the problem is not from bad connection.
For now I'm using animation and models from Stealth project. This is for testing only, of course.
Did you get any insight on this? I am facing a similar problem.
Answer by Aithoneku · Dec 02, 2014 at 07:45 AM
@AxelMGarcia I was "just" learning Unity that time, so I let it go after some time and never had to solve this in my job later. However I have two ways I would go if I would need to solve this problem again in future. One solution is to just give up, move the objects in fixed update and then animate according the movement, i.e. give up animation-controlled movement. This is the safe way. The another is to set "Update Mode" to "Animate Physics" in Animator component - this 'solution' needs investigation whether it actually works or not. According execution order ( http://docs.unity3d.com/Manual/ExecutionOrder.html ) it should NOT work. Animator component documentation does not specify this (in fact, it's apparently outdated), however script documentation ( http://docs.unity3d.com/ScriptReference/AnimatorUpdateMode.html ) says that it actually DOES update during fixed update instead of standard way. Please, let me know if you try it.
Your answer
Follow this Question
Related Questions
Mecanim Root Motion + Networking 2 Answers
Unity networking tutorial? 6 Answers
Unity Photon: animation syncing 1 Answer
How do you sync animations in Photon? 0 Answers
Network rotation is laggy and slow 2 Answers