So I’ve found that the character replication only works when using AddMovementInput or AddControllerYawInput and replicating the rotation code I had with AddControllerYawInput is giving me an equally painful headache.
Here’s the code for doing what you’ve suggested above, unfortunately I’m getting the same problem. Even though the value of CurrentForwardSpeed is changing on both clients the connected client is only moving on it’s own screen, not on the hosting client.
UPROPERTY(Transient, Replicated)
float CurrentForwardSpeed;
UFUNCTION(Reliable, Server, WithValidation)
void ServerMoveForward(float Val);
========================
void ATestPlayerController::MoveForward(float Val)
{
ServerMoveForward(Val);
}
bool ATestPlayerController::ServerMoveForward_Validate(float Val)
{
return true;
}
void ATestPlayerController::ServerMoveForward_Implementation(float Val)
{
bHasForwardInput = !FMath::IsNearlyEqual(Val, 0.f);
float CurrentAcc = bHasForwardInput ? (Val * Acceleration) : 0.0f;
float NewForwardSpeed = CurrentForwardSpeed + (GetWorld()->GetDeltaSeconds() * CurrentAcc);
CurrentForwardSpeed = FMath::Clamp(NewForwardSpeed, -MaxSpeed, MaxSpeed);
CurrentForwardValue = Val;
}
void ATestPlayerController::PlayerTick(float DeltaSeconds)
{
const FVector LocalMove = FVector(CurrentForwardSpeed * DeltaSeconds, CurrentRightSpeed * DeltaSeconds, 0.f);
GetPawn()->SetActorLocation(GetPawn()->GetActorLocation() + LocalMove, true);
}