Add SplineCameraVolume
This commit is contained in:
parent
f1a71a0a0e
commit
66a782609d
|
@ -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)
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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()));
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
};
|
Loading…
Reference in New Issue