Hi,
So I am trying to add replication to a drone simulator demo I am working on, this is the motivation for using Add Force.
But to simplify things I have created a small prototype featuring a Character with “Character Movement Component” and just trying to move two instances of that character on listen server + Client.
The two gray cubes are Server & Client. The cubes are skeletal meshes on the Character.
When I move the server, everything is smooth and fine but on the client its Jittering.
On the player controller when WSAD is pushed output is generated to the Character and sent via a non replicated event “Client_SetMovementDirection”.
Player controller.
On the Character two float replicated variables for direction is updated.
Then in the “Event tick” function a resulting force is calculated. Then this force is applied to a “Event on Owning Client” + “On Server”.
Character
Calculate Force
Character Movement Component
I do not fully understand where I am going wrong here…
Edit:
So I tested to do the same thing but with CMC AddMovement and that seems to work already.
Seems you do not even have to have authority checks when using that.
Thanks
CMC is fully networked and implements client-side prediction for all the basic movements.
The jitter you were getting was caused by server correction.
Thanks for the Reply.
That explains the snapping back.
When I call the AddMovement from Character Blueprint I have no issues with corrections.
However using AddForce calling it the same way I get correction issues.
What is the correct way to use movement components add force?
Character class fully implements the Add Movement Input functionality. The server (Authoritative Proxy) will mirror the input action do to CMC’s client-side prediction implementation.
Using Add Force requires you to do your own networking. Either Lockstep: apply on server and replicate the servers result, OR Implement your own client-side prediction (CSP).
The CMC docs have a full walkthrough of what happens on input. I highly suggest reading it fully. CSP is complex.
So the end goal is to have replicated server authorative 6DoF movement based character.
Starting the journey I switched to C++ and worked on a custom CMC. But like you mentioned @Rev0verDrive Client side prediction is not easy. My implementation worked great with no network emulation. But with emulation or on a real network once there was package loss there was a lot of corrections.
The more I read and looked in the source code I realized that rotation and movement input vector already is replicated. Should not have to do that twice.
Guess I needed to fail a few times and read through the code to understand what is going on.
Anyway I compared my projects performance to the Third-person-example and the difference was huge.
This lead me to use AddMovementInput & AddRotation functions that the 3rd person example uses. There was an issue with rotation though, gimbal-lock happens when rotating pitch axis.
Browsing the forums here and experimenting I eventually override the AddRotation functions with implementations that uses Quaternions for rotation.
The same also had to be done to the player camera manager.
Then I let the custom CMC handle static forces like gravity and in the future air resistance.
Here is the example project:
I will however go back to the CMC approach in the future to get that working and make an example of that as well.