void ADebugCameraController::ApplySpeedScale() { ASpectatorPawn* Spectator = GetSpectatorPawn(); if (Spectator) { USpectatorPawnMovement* SpectatorMovement = Cast<USpectatorPawnMovement>(Spectator->GetMovementComponent()); if (SpectatorMovement) { SpectatorMovement->MaxSpeed = InitialMaxSpeed * SpeedScale; SpectatorMovement->Acceleration = InitialAccel * SpeedScale; SpectatorMovement->Deceleration = InitialDecel * SpeedScale; } } }
void UBerserkCameraComponent::UpdateCameraMovement(const APlayerController* playerController) { auto const* const localPlayer = Cast<ULocalPlayer>(playerController->Player); if (localPlayer && localPlayer->ViewportClient && localPlayer->ViewportClient->Viewport) { FVector2D mousePosition; if (localPlayer->ViewportClient->GetMousePosition(mousePosition) == false) return; auto viewport = localPlayer->ViewportClient->Viewport; const float scrollSpeed = 60.0f; const FIntPoint viewportSize = viewport->GetSizeXY(); const uint32 viewLeft = FMath::TruncToInt(localPlayer->Origin.X * viewportSize.X); const uint32 viewRight = viewLeft + FMath::TruncToInt(localPlayer->Size.X * viewportSize.X); const uint32 viewTop = FMath::TruncToInt(localPlayer->Origin.Y * viewportSize.Y); const uint32 viewBottom = viewTop + FMath::TruncToInt(localPlayer->Size.Y * viewportSize.Y); const float maxSpeed = CameraScrollSpeed * FMath::Clamp(ZoomAlpha, 0.3f, 1.0f); bool isNoScrollZone = false; const FVector mouseCoords(mousePosition, 0.0f); for (int iZone = 0; iZone < NoScrollZones.Num(); ++iZone) { const auto eachZone = NoScrollZones[iZone]; if (eachZone.IsInsideXY(mouseCoords) == true) isNoScrollZone = true; } const uint32 mouseX = mousePosition.X; const uint32 mouseY = mousePosition.Y; float spectatorCameraSpeed = maxSpeed; ASpectatorPawn* spectatorPawn = nullptr; if (GetPlayerController() != nullptr) { spectatorPawn = GetPlayerController()->GetSpectatorPawn(); if (spectatorPawn->GetMovementComponent() != nullptr) spectatorCameraSpeed = GetDefault<UBerserkSpectatorPawnMovement>(spectatorPawn->GetMovementComponent()->GetClass())->MaxSpeed; } if (!isNoScrollZone) { if (mouseX >= viewLeft && mouseX <= (viewLeft + CameraActiveBorder)) { const float delta = 1.0f - float(mouseX - viewLeft) / CameraActiveBorder; spectatorCameraSpeed = delta * maxSpeed; MoveRight(-scrollSpeed * delta); } else if (mouseX >= (viewRight - CameraActiveBorder) && mouseX <= viewRight) { const float delta = float(mouseX - viewRight + CameraActiveBorder) / CameraActiveBorder; spectatorCameraSpeed = delta * maxSpeed; MoveRight(scrollSpeed * delta); } if (mouseY >= viewTop && mouseY <= (viewTop + CameraActiveBorder)) { const float delta = 1.0f - float(mouseY - viewTop) / CameraActiveBorder; spectatorCameraSpeed = delta * maxSpeed; MoveForward(scrollSpeed * delta); } else if (mouseY >= (viewBottom - CameraActiveBorder) && mouseY <= viewBottom) { const float delta = float(mouseY - (viewBottom - CameraActiveBorder)) / CameraActiveBorder; spectatorCameraSpeed = delta * maxSpeed; MoveForward(-scrollSpeed * delta); } if (spectatorPawn != nullptr) { UFloatingPawnMovement* floatingMovementComponent = Cast<UFloatingPawnMovement>(spectatorPawn->GetMovementComponent()); if (floatingMovementComponent) floatingMovementComponent->MaxSpeed = spectatorCameraSpeed; } } } NoScrollZones.Empty(); }