Hello everyone!
I have an issue with rotating character in multiplayer. The character owned by listen server rotates just as expected (on both server and clients) but for some reason the rotation of character owned by client is way too slow.
You can check video of the issue here
The function that I am using to rotate the character:
bool APlayerCharacter::DeltaRotatePlayerToDesiredYaw(float DesiredYaw, float DeltaTime, float RotationRate)
{
float CurrentYaw = GetActorRotation().Yaw;
bool Result = FMath::IsNearlyEqual(CurrentYaw, DesiredYaw, 0.1f);
if (Result)
{
SetCharacterRotation(FRotator(0.f, DesiredYaw, 0.f));
return true;
}
else
{
float YawDiff = FMath::FindDeltaAngleDegrees(CurrentYaw, DesiredYaw);
float Multiplier = YawDiff / FMath::Abs(YawDiff);
float RotateBy = Multiplier * RotationRate * DeltaTime;
if (FMath::Abs(YawDiff) <= FMath::Abs(RotateBy) + 0.5f)
{
SetCharacterRotation(FRotator(0.f, DesiredYaw, 0.f));
return true;
}
else
{
SetCharacterRotation(FRotator(0.f, CurrentYaw + RotateBy, 0.f));
return false;
}
return false;
}
}
where SetCharacterRotation
is:
void ABaseCharacter::SetCharacterRotation(FRotator NewRotation)
{
SetActorRotation(NewRotation);
if (Role < ROLE_Authority)
{
Server_SetCharacterRotation(NewRotation);
}
}
and Server_SetCharacterRotation
is a server RPC that calls SetCharacterRotation
again.
Any help in fixing this issue would be highly appreciated. Thanks!