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

@ -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)

View File

@ -27,8 +27,7 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite)
bool FollowPlayer = false;
private:
protected:
UPROPERTY()
bool IsActive = false;
@ -36,7 +35,6 @@ private:
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;
};