I started with the TopDown template but it doesn’t seem to be multiplayer ready so I did some digging.
void ATopDownPlayerController::MoveToMouseCursor()
{
// Trace to see what is under the mouse cursor
FHitResult Hit;
GetHitResultUnderCursor(ECC_Visibility, false, Hit);
if (Hit.bBlockingHit)
{
// We hit something, move there
SetNewMoveDestination(Hit.ImpactPoint);
}
}
void ATopDownPlayerController::SetNewMoveDestination_Implementation(const FVector DestLocation)
{
APawn* const Pawn = GetPawn();
if (Pawn)
{
UNavigationSystem* const NavSys = GetWorld()->GetNavigationSystem();
float const Distance = FVector::Dist(DestLocation, Pawn->GetActorLocation());
// We need to issue move command only if far enough in order for walk animation to play correctly
if (NavSys && (Distance > 120.0f))
{
NavSys->SimpleMoveToLocation(this, DestLocation);
}
}
}
void ATopDownPlayerController::OnSetDestinationPressed()
{
// set flag to keep updating destination until released
bMoveToMouseCursor = true;
}
void ATopDownPlayerController::OnSetDestinationReleased()
{
// clear flag to indicate we should stop updating the destination
bMoveToMouseCursor = false;
}
bool ATopDownPlayerController::SetNewMoveDestination_Validate(const FVector DestLocation)
{
return true;
}
And I changed the signature to
UFUNCTION(reliable, server, WithValidation)
void SetNewMoveDestination(const FVector DestLocation);
Now I want to call SetNewMoveDestination on the client and on the server. I thought I could use the function as a prediction function and when I call
SetNewMoveDestination(Hit.ImpactPoint);
It would be called on the client and the server. And if the client is too much out of sync with the server it just resets the local pawn to the servers location of the pawn.
But what happens is that the local pawn doesn’t receive any rotation update. If I am Pawn1 and Pawn1 moves I don’t get the rotation update but if Pawn2 sees Pawn1 moving he sees Pawn1 with the correct rotation.
Any idea why this happens?