Download

Odd RPC behavior

While i was working on my Character turn function, i noticed a few things that i hope someone will explain them to me…

Here is my code:

void AMyCharacter::CharacterTurn(float AxisRate)
{
    if (GetController() != NULL && AxisRate)
    {
        float DeltaYaw = AxisRate * BaseTurnAroundRate * GetWorld()->GetDeltaSeconds();
        AddControllerYawInput(DeltaYaw / 2);

        FRotator NewRot = GetActorRotation();
        NewRot.Yaw = DeltaYaw * CastChecked<APlayerController>(Controller)->InputYawScale;
        SetActorRotation(NewRot); //  < -- If You comment this line, RPC doesn't work

	    // Server RPC
	    Request_S_Turn(NewRot);
    }
}

void AMyCharacter::Request_S_Turn_Implementation(FRotator NewRot)
{
    SetActorRotation(NewRot);
}

First:

So… what i found is… when i pass NewRot as parameter, the SetActorRotation() in the RPC implementation function doesn’t work without calling the SetActorRotation() in the CharacterTurn() function.

If i use float value instead of FRotator as parameter, the problem disappears. Like this:

// Server RPC
Request_S_Turn(DeltaYaw);

void AMyCharacter::Request_S_Turn_Implementation(float TurnRate)
{
    FRotator NewRot = GetActorRotation();
    NewRot.Yaw = TurnRate* CastChecked<APlayerController>(Controller)->InputYawScale;
    SetActorRotation(NewRot);
}

Why is that??

Second:

The speed of AddControllerYawInput() and the RPC SetActorRotation() is the same while using DeltaYaw… (the Camera and character on server make the 360 degrees turn in approx. 4 seconds)

However, the non-RPC SetActorRotation() when called locally on client turns two-times slower for unknown reason…

Thats why i have to divide the DeltaYaw parameter by 2.

AddControllerYawInput(DeltaYaw / 2);

// Server RPC
Request_S_Turn(DeltaYaw / 2);

Why is the character so slow on client??