Initial Project Setup
This commit is contained in:
34
Source/MyProject3/CameraFollowActor.cpp
Normal file
34
Source/MyProject3/CameraFollowActor.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
// CameraFollowActor.cpp
|
||||
#include "CameraFollowActor.h"
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "GameFramework/Actor.h"
|
||||
|
||||
// Sets default values
|
||||
ACameraFollowActor::ACameraFollowActor()
|
||||
{
|
||||
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
||||
PrimaryActorTick.bCanEverTick = true;
|
||||
|
||||
// Create the camera component
|
||||
CameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComponent"));
|
||||
RootComponent = CameraComponent;
|
||||
}
|
||||
|
||||
// Called when the game starts or when spawned
|
||||
void ACameraFollowActor::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
void ACameraFollowActor::Tick(float DeltaTime)
|
||||
{
|
||||
Super::Tick(DeltaTime);
|
||||
|
||||
if (TargetActor)
|
||||
{
|
||||
// Update the camera position to follow the target actor with the specified offset
|
||||
FVector NewLocation = TargetActor->GetActorLocation() + CameraOffset;
|
||||
SetActorLocation(NewLocation);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user