Add Camera Volume
This commit is contained in:
parent
3678ce7e1d
commit
5be0c02e69
|
@ -0,0 +1,32 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "CameraVolume.h"
|
||||||
|
#include "TankPlayerCharacter.h"
|
||||||
|
|
||||||
|
ACameraVolume::ACameraVolume()
|
||||||
|
{
|
||||||
|
ArrowComponent = CreateDefaultSubobject<UArrowComponent>(TEXT("Arrow Component"));
|
||||||
|
ArrowComponent->SetupAttachment(RootComponent);
|
||||||
|
|
||||||
|
DebugCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("Debug Camera"));
|
||||||
|
DebugCamera->SetupAttachment(ArrowComponent);
|
||||||
|
DebugCamera->SetActive(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ACameraVolume::BeginPlay()
|
||||||
|
{
|
||||||
|
Super::BeginPlay();
|
||||||
|
this->OnActorBeginOverlap.AddDynamic(this, &ACameraVolume::OnBeginOverlap);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ACameraVolume::OnBeginOverlap(AActor* OverlappedActor, AActor* OtherActor)
|
||||||
|
{
|
||||||
|
if (ATankPlayerCharacter* PlayerCharacter = Cast<ATankPlayerCharacter>(OtherActor))
|
||||||
|
{
|
||||||
|
FTransform transform = PlayerCharacter->CameraComponent->GetComponentTransform();
|
||||||
|
transform.SetLocation(ArrowComponent->GetComponentTransform().GetLocation());
|
||||||
|
transform.SetRotation(ArrowComponent->GetComponentTransform().GetRotation());
|
||||||
|
PlayerCharacter->CameraComponent->SetWorldTransform(transform);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,34 @@
|
||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "Camera/CameraComponent.h"
|
||||||
|
#include "Components/ArrowComponent.h"
|
||||||
|
#include "Engine/TriggerVolume.h"
|
||||||
|
#include "CameraVolume.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
UCLASS(Blueprintable)
|
||||||
|
class TANK_API ACameraVolume : public ATriggerVolume
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
|
||||||
|
public:
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
UArrowComponent* ArrowComponent;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
UCameraComponent* DebugCamera;
|
||||||
|
|
||||||
|
ACameraVolume();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
UFUNCTION()
|
||||||
|
void OnBeginOverlap(AActor* OverlappedActor, AActor* OtherActor);
|
||||||
|
};
|
|
@ -14,6 +14,7 @@ ATankPlayerCharacter::ATankPlayerCharacter()
|
||||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||||
PrimaryActorTick.bCanEverTick = true;
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
|
||||||
|
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera Component"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
|
#include "Camera/CameraComponent.h"
|
||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "TankPlayerCharacter.generated.h"
|
#include "TankPlayerCharacter.generated.h"
|
||||||
|
|
||||||
|
@ -26,6 +27,9 @@ public:
|
||||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||||
UInputAction* YawAction;
|
UInputAction* YawAction;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||||
|
UCameraComponent* CameraComponent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this character's properties
|
// Sets default values for this character's properties
|
||||||
ATankPlayerCharacter();
|
ATankPlayerCharacter();
|
||||||
|
|
Loading…
Reference in New Issue