I have my animations setup on Networked characters so that they blend between walking and running based on a speed variable. I move the characters position in code. I have a small skating issue, but I should be able to fix this.
I was however considering changing to use Mecanim’s root motion. I am not sure how this would work with a networked character?
I thought there would be plenty of discussion about this in the forums, but a search didn’t turn up any solid advice.
My question is, for networked characters, is it better to use root motion or apply movement to character in code and sync animations with speed variables?
What’s your network architecture? If it’s a pure authoritative server, you should probably stick with movement solely in code. If you’re using client-side prediction, you can probably use root motion, but you’ll have to decide how to handle position resynchronization with the server – jump to the server’s authoritative position, or root motion there somehow? And if you’re using a non-authoritative server, you can go root motion all the way for the local player, with the same concerns for other players.
My Architecture is sort of Authoritative. Player position is handled on each client using user input. The players position is sent to the server 20 times a second. Server validates position, and will reject if cheating is detected, if Ok, will send position update to other players. On the avatar I interpolate position between last 2 known position updates, extrapolation is used if a packet is dropped.
If I use root motion, I can play animations to move the avatar towards the calculated position. But as you point out, I will need to handle resynchronization when the avatars position gets too far from the calculated position. Resynchronization is ugly, because it inevitably looks like a stutter in the characters movement.
I was also concerned that root motion may add additional lag between avatars position and remote players actual position. Because I don’t just move the player to the calculated position, I play an animation to move towards the calculated position.
The reason I was considering using root motion, is I thought it might give more natural looking movement? This is because you are always constrained to moving within the animations limits. As opposed to just moving the character around and playing an animation over the top.
Sorry, that’s all I got. I haven’t done much with root motion in multiplayer. Fairly recently I dug into Bolt with Realistic FPS Prefab, but the local player is body-less first person, so I didn’t use root motion for it. And for remote players I immediately snapped them to the “authoritative” position since I figured in a fast shooter accurate aiming was more important than natural-looking movement. Try it out and let us know how it works out!
Well, I think you are right that root motion would be more natural looking with no skating. Even if you speed up the animation, you are still only moving the distance dictated by the movement in root motion. All that said, you can handle skating issues fairly well just by timing the walk/run to your speed. As the speed increase, so should the speed of the animation. I’m not a coder, so I tend to use root motion in my demos. 1 thing I tend to find, is that root motion, with accurate foot step distances, feels ridiculously slow to me and I tend to speed them up. Maybe it’s just me tho. lol
I keep reading that it is advised to not use root motion on an authoritative server, but I’ve played an MMO that used root motion and it was great, so I think it can be done if you are careful and clever. But I have not tried it myself.
I decided to stick with the code movement and synchronizing animations. It does take some time to get this looking good, but i am pleased with the results.
I found that all animations aren’t created equal. I have a few packages from the asset store. But I couldn’t get good results from them. I am now using Mixamo animations, which just work and look good. Unfortunately they are expensive.
I made that comment seven years ago. I’m not sure what I was thinking about.
But if you are using root motion, your network speeds are going to be faster than your frame rate, so you should be able to work out some form of synchronization and correction.