Add SplineCameraVolume

This commit is contained in:
baz 2024-06-06 00:12:02 +01:00
parent f1a71a0a0e
commit 66a782609d
4 changed files with 64 additions and 8 deletions

View File

@ -10,7 +10,7 @@
ACameraVolume::ACameraVolume()
{
PrimaryActorTick.bCanEverTick = true;
ArrowComponent = CreateDefaultSubobject<UArrowComponent>(TEXT("Arrow Component"));
ArrowComponent->SetupAttachment(RootComponent);
@ -23,7 +23,7 @@ void ACameraVolume::BeginPlay()
{
Super::BeginPlay();
this->OnActorBeginOverlap.AddDynamic(this, &ACameraVolume::OnBeginOverlap);
this->OnActorEndOverlap.AddDynamic(this, &ACameraVolume::ACameraVolume::OnEndOverlap);
this->OnActorEndOverlap.AddDynamic(this, &ACameraVolume::OnEndOverlap);
}
void ACameraVolume::Tick(float DeltaSeconds)
@ -62,7 +62,7 @@ void ACameraVolume::OnBeginOverlap(AActor* OverlappedActor, AActor* OtherActor)
{
TankPlayerCharacter = PlayerCharacter;
IsActive = true;
auto CameraManagerSubsystem = GetGameInstance()->GetSubsystem<UCameraManagerSubsystem>();
CameraManagerSubsystem->SetCurrentCameraVolume(this);
}
@ -72,7 +72,7 @@ void ACameraVolume::OnEndOverlap(AActor* OverlappedActor, AActor* OtherActor)
{
IsActive = false;
TankPlayerCharacter = nullptr;
auto CameraManagerSubsystem = GetGameInstance()->GetSubsystem<UCameraManagerSubsystem>();
CameraManagerSubsystem->RemoveCameraVolume(this);
}

View File

@ -26,17 +26,15 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool FollowPlayer = false;
private:
protected:
UPROPERTY()
bool IsActive = false;
UPROPERTY()
ATankPlayerCharacter* TankPlayerCharacter = nullptr;
public:
ACameraVolume();
protected:

View File

@ -0,0 +1,31 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "SplineCameraVolume.h"
#include "Kismet/KismetMathLibrary.h"
ASplineCameraVolume::ASplineCameraVolume()
{
SplineComponent = CreateDefaultSubobject<USplineComponent>(TEXT("Spline Component"));
SplineComponent->SetupAttachment(RootComponent);
FollowPlayer = true;
}
void ASplineCameraVolume::BeginPlay()
{
Super::BeginPlay();
}
void ASplineCameraVolume::Tick(float DeltaSeconds)
{
if (IsActive && FollowPlayer && TankPlayerCharacter)
{
FVector Location = SplineComponent->FindLocationClosestToWorldLocation(
TankPlayerCharacter->GetTransform().GetLocation(), ESplineCoordinateSpace::World);
TankPlayerCharacter->CameraComponent->SetWorldLocation(Location);
TankPlayerCharacter->CameraComponent->SetWorldRotation(UKismetMathLibrary::FindLookAtRotation(
Location, TankPlayerCharacter->GetTransform().GetLocation()));
}
}

View File

@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "CameraVolume.h"
#include "Components/SplineComponent.h"
#include "SplineCameraVolume.generated.h"
/**
*
*/
UCLASS()
class TANK_API ASplineCameraVolume : public ACameraVolume
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
USplineComponent* SplineComponent;
ASplineCameraVolume();
virtual void BeginPlay() override;
virtual void Tick(float DeltaSeconds) override;
};