Download

Rotation replication problem

By gameplay reasons i have to control players rotation on server.
But when i rotate my character i get this lags:

Movement replicated:
replicated
Maybe on gif this looks not terrible, but it is

Same thing but Replicate Movement disabled:
not_replicated
Everything smooth.

I’m not sure what to do with it. Seems like when Replicate Movement is enabled, server trying to correct my rotation and this leads to lags.

I tried many many things, but still can’t make this work properly

Any help will be much appreciated

This is how i rotate my character (func called in tick):
0.666 on server was found randomly and gives most correct client/server rotation speed. Also changing or removing this value not helps with this problem.

    if(IsLocallyControlled() || GetNetMode() == NM_DedicatedServer)
	{
		const FRotator CurrentRotator = FRotator(0, GetActorRotation().Yaw, 0);
		const FRotator TargetRotator = FRotator(0, GetControlRotation().Yaw, 0);

		float InterpolationSpeed = 5.0f;
		
		if(GetNetMode() == NM_DedicatedServer)
		{
			const FRotator DesiredRotation = FMath::RInterpTo(CurrentRotator, TargetRotator, 0.01, InterpolationSpeed * 0.666);
			SetActorRotation(DesiredRotation);
		}
		else
		{
			const FRotator DesiredRotation = FMath::RInterpTo(CurrentRotator, TargetRotator, 0.01, InterpolationSpeed);
			SetActorRotation(DesiredRotation);
		}
	}

So you’re saying you accept input for the Client cam, send it to the Server for processing / checking, then send it back to the client where the cam THEN gets rotated / updated, and you’re saying there’s lag? If yes, what did you expect dude! :stuck_out_tongue: That’s what client-side prediction / validation is about. You can’t move anything this way without lag, not player camera, not player vehicle, not the player themselves. :wink: Everything has be done locally for smooth movement, but the Server can still check and override / correct invalid moves!

Im not rotating camera via server.
Im rotating only characters based on camera rotation.

So when i rotate camera, this goes to server.
Then server gets Camera( Control ) Rotation and rotate character to this rotation.
Then Replicated Movement share rotation on server to other clients.

In my code you can see i rotate own character locally.

It’s not that expensive, and it’s actually works. I have problem with lags only on own client, other clients see this smoothly as expected.

other_clien2

Quick observations… Reading the code it looks like it will set the Rotation locally (IsLocallyControlled → SetActorRotation) on the local Client. But it will then execute again on the Server’s copy of the Character, setting the rotation once again, replicating to everybody via CMC, clashing with whatever the local Client has done.

This should work fine and expected on remote clients though, as they will ONLY SEE what the Server replicates. So lag won’t be obvious, as remote clients won’t be aware of any input lag response time on the local Client. Especially if this is only being tested on a local LAN without bumping any of the Packet Lag / Loss console commands.

Then there’s the issue of how you’re actually sending the Input info to the Server. RPC on Tick is probably going to bring even more problems. Overall, just a gut feeling here, but I would abandon this approach and try to find sample code on github or wherever, that comes close to what you want. As I don’t think this is going to work. It doesn’t matter if you’re rotating camera or character, there will be lag. Anyway, good luck!

Okay i’m stupid

I tried to recreate something that already exists and working perfectly.

GetCharacterMovement()->bUseControllerDesiredRotation = true;
GetCharacterMovement()->RotationRate = FRotator(0,270,0);

This setup works exactly the same as my code above, but it does not lag