UE4 Sprint jitter.

I have this function to handle sprinting:



void ADynamixCPPCharacter::StartSprint_Implementation()
{
sprinting = !sprinting;
if (sprinting) {
GetCharacterMovement()->MaxWalkSpeed = 3000;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Sprint"));
}
else {
GetCharacterMovement()->MaxWalkSpeed = baseWalkSpeed;
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Stop Sprint"));
}
}


When I sprint in the game, and when connected to a server, it jitters. Using (basically) the same code in blueprints does not have this effect. It is replicated to the server, Unreliably.

What am I doing wrong?

Here is the UFUNCTION definition:



UFUNCTION(Uneliable, Server, WithValidation)
void StartSprint();
void StartSprint_Implementation();
bool StartSprint_Validate();


StartSprint_Validate jsut returns true
and the input action that it is bound to:


PlayerInputComponent->BindAction("Sprint", IE_Pressed, this, &ADynamixCPPCharacter::StartSprint);

My unreal engine version is 4.25

Well without seeing more of how this is working I can only guess. In general I have found that movement “Jitters” are almost always a difference in velocity between the server and the client. If this function is fired only once (say button pressed event) and replicates “unreliably” that could be a problem in itself, but if that function is fired on tick than the unreliable tag is appropriate (Never run reliable functions on tick, and only ever try to have at most one unreliable RPC on tick). Generally all my to server RPCs that handle input are reliable (except for the ones that continuously fire of course).

Sorry for not including it but here is the InputAction bound to it:


PlayerInputComponent->BindAction("Sprint", IE_Pressed, this, &ADynamixCPPCharacter::StartSprint);

I just tried to set it to Reliable, and it makes no difference.

The only other part pertaining to this function is in the .h file:


UFUNCTION(Unreliable, Server, WithValidation)
void StartSprint();
void StartSprint_Implementation();
bool StartSprint_Validate();


StartSprint_Validate jsut returns true

Thanks for your reply.

The jittering you are experiencing comes from the network corrections the MovementComponent on your Character performs automatically.

Like all other MovementTypes (Jumping, Crouching, etc.) sprinting should also be implemented using the MovementComponent, you can find tutorials on how to do this correctly here:

https://docs.unrealengine.com/en-US/…ent/index.html

https://michaeljcole.github.io/wiki…cter_Movement/

+1 on this. This is exactly what came to my mind when I read the OP.

Thank you for your answers! I am going to try @Elyy 's answer as soon as I can.