This article aims to serve fellow multiplayer game developers that are struggling to achieve smooth replication on quick movements. I know I have. Therefore I took the time to have a simple and to-the-point article with a solution for this issue that I wish I had found easily at the time.
As we all know, multiplayer games are challenging as all developments must take replication and authority into account at the feature planning phase, for many reasons but mainly for security(important logic checks server side) and both for smooth replicated gameplay, to provide an enjoyable experience all around.
As our game progressed and features were added, we aimed to have the character dashing around the map.
That was not so simple.
We have tried the standard logical solution:
Character position is replicated
for the dash duration, we increase the speed of the character by increasing MaxWalkSpeed
once the dash duration end, we decrease the speed back down to the character's normal speed.
Sounds good, doesn’t work. we had jittering all around
In order to try and fix this, we have tried multiple other things, such as:
manual replication with interpolation on tick
increasing net priority
use root motion animation instead of increasing MaxWalkSpeed
have the root motion animation play locally for all clients
many others
Still could not find the correct combination for the desired result. some were better than others, but they were all jittering to some degree.
After a lot of digging around in various sites and forums, I have picked up various pieces to help me build the smooth replication we aim for, using 3 ingredients:
Root motion animation
After playing around with various combinations, the solution was the following:
Set the dash animation with root motion
set bIgnoreClientMovementErrorChecksAndCorrection and bServerAcceptClientAuthoritativePosition of CharacterMovementComponent to true- run on server
Play the dash animation on all clients - multicast
When the animation ends, set bIgnoreClientMovementErrorChecksAndCorrection and bServerAcceptClientAuthoritativePosition of CharacterMovementComponent to false- run on server
We are basically giving temporary movement control to the client, and disabling server corrections.
playing a root motion animation on all clients locally (and it plays smoothly as there are no corrections for this character)
animation ends. enabling back movement replication from server side.
One note regarding - bServerAcceptClientAuthoritativePosition - this actually gives position control to the client and, therefore, could be potentially exploited. implement some safeguards such as distance calculation in order to prevent people from trying to travel around the map through this short duration
The result with 2 clients:
Blueprint example:
Commenti