void UTDCSpectatorPawnMovement::TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) { Super::TickComponent(DeltaTime, TickType, ThisTickFunction); if (!PawnOwner || !UpdatedComponent) { return; } APlayerController* PlayerController = Cast<APlayerController>(PawnOwner->GetController()); if (PlayerController && PlayerController->IsLocalController()) { if (!bInitialLocationSet) { PawnOwner->SetActorRotation(PlayerController->GetControlRotation()); PawnOwner->SetActorLocation(PlayerController->GetSpawnLocation()); bInitialLocationSet = true; } FVector MyLocation = UpdatedComponent->GetComponentLocation(); ATDCSpectatorPawn* SpectatorPawn = Cast<ATDCSpectatorPawn>(PlayerController->GetSpectatorPawn()); if ((SpectatorPawn != NULL) && (SpectatorPawn->GetCameraComponent() != NULL)) { SpectatorPawn->GetCameraComponent()->ClampCameraLocation(PlayerController, MyLocation); } UpdatedComponent->SetWorldLocation(MyLocation, false); } }
void AGameModeBase::HandleSeamlessTravelPlayer(AController*& C) { // Default behavior is to spawn new controllers and copy data APlayerController* PC = Cast<APlayerController>(C); if (PC && PC->Player) { // We need to spawn a new PlayerController to replace the old one APlayerController* NewPC = SpawnPlayerController(PC->IsLocalPlayerController() ? ROLE_SimulatedProxy : ROLE_AutonomousProxy, PC->GetFocalLocation(), PC->GetControlRotation()); if (NewPC) { PC->SeamlessTravelTo(NewPC); NewPC->SeamlessTravelFrom(PC); SwapPlayerControllers(PC, NewPC); PC = NewPC; C = NewPC; } else { UE_LOG(LogGameMode, Warning, TEXT("Failed to spawn new PlayerController for %s (old class %s)"), *PC->GetHumanReadableName(), *PC->GetClass()->GetName()); PC->Destroy(); return; } } InitSeamlessTravelPlayer(C); // Initialize hud and other player details, shared with PostLogin GenericPlayerInitialization(C); if (PC) { // This may spawn the player pawn if the game is in progress HandleStartingNewPlayer(PC); } }