Skip to content
Snippets Groups Projects
Commit 16faf273 authored by Kris Tabea Helwig's avatar Kris Tabea Helwig
Browse files

Adds option to make distance traveled between ticks constant

parent 5a26fefa
No related branches found
No related tags found
1 merge request!1Implements `PointOfInterest`s
...@@ -99,6 +99,8 @@ void APointOfInterestManager::StartCameraRide() ...@@ -99,6 +99,8 @@ void APointOfInterestManager::StartCameraRide()
{ {
CameraRideStart = UGameplayStatics::GetTimeSeconds(this); CameraRideStart = UGameplayStatics::GetTimeSeconds(this);
CameraRideEnd = CameraRideStart + SplineComponent->Duration; CameraRideEnd = CameraRideStart + SplineComponent->Duration;
CurrentUpdate = 0;
DurationInUpdates = static_cast<int>(SplineComponent->Duration * CameraRideSecondsToUpdates);
IsRidingCamera = true; IsRidingCamera = true;
} }
...@@ -161,7 +163,7 @@ void APointOfInterestManager::ProgressCameraRide() ...@@ -161,7 +163,7 @@ void APointOfInterestManager::ProgressCameraRide()
{ {
double Current = UGameplayStatics::GetTimeSeconds(this); double Current = UGameplayStatics::GetTimeSeconds(this);
float SecondsSinceStart = Current - CameraRideStart; float SecondsSinceStart = Current - CameraRideStart;
UE_LOGFMT(POIManagerLog, VeryVerbose, ""); CurrentUpdate++;
APawn* Pawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0); APawn* Pawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
if (!Pawn) if (!Pawn)
...@@ -169,6 +171,26 @@ void APointOfInterestManager::ProgressCameraRide() ...@@ -169,6 +171,26 @@ void APointOfInterestManager::ProgressCameraRide()
UE_LOGFMT(POIManagerLog, Warning, "Attempted to move player pawn but no pawn found to move."); UE_LOGFMT(POIManagerLog, Warning, "Attempted to move player pawn but no pawn found to move.");
return; return;
} }
if (MakeCameraRideProgressionConstantBetweenTicks)
{
if (CurrentUpdate < DurationInUpdates)
{
float CurrentTime = 1.0f * CurrentUpdate / CameraRideSecondsToUpdates;
FVector Location = SplineComponent->GetLocationAtTime(CurrentTime, ESplineCoordinateSpace::World);
FRotator Rotation = SplineComponent->GetRotationAtTime(CurrentTime, ESplineCoordinateSpace::World);
Rotation.Pitch = 0;
Rotation.Roll = 0;
Pawn->Controller->SetControlRotation(Rotation);
Pawn->SetActorLocationAndRotation(Location, Rotation);
}
else
{
CameraRideEnded();
}
}
else
{
if (Current < CameraRideEnd) if (Current < CameraRideEnd)
{ {
FVector Location = SplineComponent->GetLocationAtTime(SecondsSinceStart, ESplineCoordinateSpace::World); FVector Location = SplineComponent->GetLocationAtTime(SecondsSinceStart, ESplineCoordinateSpace::World);
...@@ -184,6 +206,7 @@ void APointOfInterestManager::ProgressCameraRide() ...@@ -184,6 +206,7 @@ void APointOfInterestManager::ProgressCameraRide()
CameraRideEnded(); CameraRideEnded();
} }
} }
}
void APointOfInterestManager::CameraRideEnded() void APointOfInterestManager::CameraRideEnded()
{ {
......
...@@ -42,6 +42,21 @@ public: ...@@ -42,6 +42,21 @@ public:
UFUNCTION(BlueprintCallable, Category="Point Of Interest Manager") UFUNCTION(BlueprintCallable, Category="Point Of Interest Manager")
int GetPointOfInterestCount(); int GetPointOfInterestCount();
/**
* Whether the camera should progress a constant distance between ticks (true) or a variable distance based on frametimes (false).
* This should be set to true if you expect long/inconsistent frame times or for e.g. PSO gathering.
*/
UPROPERTY(EditAnywhere, Category="Point Of Interest Manager")
bool MakeCameraRideProgressionConstantBetweenTicks = true;
/**
* Only relevant when MakeCameraRideProgressionConstantBetweenTicks = true.
* The conversion rate of how many ticks the camera should update to equal the distance traveled during 1 second.
*/
UPROPERTY(EditAnywhere, Category="Point Of Interest Manager",
meta = (EditCondition = "MakeCameraRideProgressionConstantBetweenTicks"))
int CameraRideSecondsToUpdates = 60;
protected: protected:
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
TArray<APointOfInterest*> POIs; TArray<APointOfInterest*> POIs;
...@@ -61,4 +76,5 @@ private: ...@@ -61,4 +76,5 @@ private:
float CameraSpeed = 100; float CameraSpeed = 100;
bool IsRidingCamera; bool IsRidingCamera;
float CameraRideStart, CameraRideEnd; float CameraRideStart, CameraRideEnd;
int DurationInUpdates, CurrentUpdate;
}; };
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment