First camera system; follows midpoint of both character's Y and Z pos

First camera system; follows midpoint of both character's Y and Z pos
This commit is contained in:
Kevin Poretti 2022-01-15 19:19:22 -05:00
parent ef03c80ca8
commit 6e0c181014
8 changed files with 100 additions and 33 deletions

1
.gitignore vendored
View File

@ -68,3 +68,4 @@ Build/*/**
# Cache files for the editor to use
**/DerivedDataCache/*
Scratch

BIN
KOFForever/Content/Core/BP_DefaultCamera.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
KOFForever/Content/Maps/TestMap.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -9,7 +9,8 @@
"Type": "Runtime",
"LoadingPhase": "Default",
"AdditionalDependencies": [
"Paper2D"
"Paper2D",
"Engine"
]
}
]

View File

@ -0,0 +1,36 @@
#include "Camera/KOFDefaultCamera.h"
#include "DrawDebugHelpers.h"
#include "Camera/CameraComponent.h"
AKOFDefaultCamera::AKOFDefaultCamera()
{
PrimaryActorTick.bCanEverTick = true;
MinFOV = 80.0f;
MaxFOV = 85.0f;
GetCameraComponent()->SetFieldOfView(MinFOV);
HeightOffset = 60.0f;
ZAveragingFactor = 2.0f;
}
void AKOFDefaultCamera::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
check(P1);
check(P2);
FVector P1Loc = P1->GetActorLocation();
FVector P2Loc = P2->GetActorLocation();
FVector CameraLoc = GetActorLocation();
FVector MidPoint = FVector(CameraLoc.X, (P1Loc.Y + P2Loc.Y) / 2.0f, ((P1Loc.Z + P2Loc.Z) / ZAveragingFactor) + HeightOffset);
SetActorLocation(MidPoint);
// set FOV
}

View File

@ -25,23 +25,6 @@ AKOFBaseCharacter::AKOFBaseCharacter()
GetCapsuleComponent()->SetCapsuleHalfHeight(96.0f);
GetCapsuleComponent()->SetCapsuleRadius(40.0f);
// Create a camera boom attached to the root (capsule)
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment(RootComponent);
CameraBoom->TargetArmLength = 500.0f;
CameraBoom->SocketOffset = FVector(0.0f, 0.0f, 0.0f);
CameraBoom->bDoCollisionTest = false;
CameraBoom->SetRelativeRotation(FRotator(0.0f, 180.f, 0.0f));
// Create an orthographic camera (no perspective) and attach it to the boom
SideViewCameraComponent = CreateDefaultSubobject<UCameraComponent>(TEXT("SideViewCamera"));
SideViewCameraComponent->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
// Prevent all automatic rotation behavior on the camera, character, and camera component
CameraBoom->SetUsingAbsoluteRotation(true);
SideViewCameraComponent->bUsePawnControlRotation = false;
SideViewCameraComponent->bAutoActivate = true;
GetCharacterMovement()->bOrientRotationToMovement = false;
// Configure character movement

View File

@ -0,0 +1,56 @@
#pragma once
#include "CoreMinimal.h"
#include "Camera/CameraActor.h"
#include "KOFDefaultCamera.generated.h"
/**
*
*/
UCLASS()
class KOFFOREVER_API AKOFDefaultCamera : public ACameraActor
{
GENERATED_BODY()
public:
AKOFDefaultCamera();
virtual void Tick(float DeltaSeconds) override;
protected:
/**
* Min FOV camera will zoom in to as character's walk farther apart from each other.
*
*
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = CameraSettings, meta = (UIMin = "5.0", UIMax = "170", ClampMin = "0.001", ClampMax = "360.0", Units = deg))
float MinFOV;
/** Max FOV camera will zoom out to as character's walk farther apart from each other */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = CameraSettings, meta = (UIMin = "5.0", UIMax = "170", ClampMin = "0.001", ClampMax = "360.0", Units = deg))
float MaxFOV;
/** Offset added to the camera's Z value after performing the character mid point calculation */
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = CameraSettings)
float HeightOffset;
/**
* Value used when averaging both character's Z positions to find the camera's final Z position.
*
* A value of 2.0 will set the camera's Z position to the midpoint between both character's Z positions.
* A value less than 2.0 will keep the camera closer to the ground even as another player jumps.
*/
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = CameraSettings)
float ZAveragingFactor;
// References to player main character's
// eventually we want to spawn all the player's characters from game mode? and then we can get the references to
// P1 and P2 from there. For now we'll just set the references manually in the level
UPROPERTY(EditAnywhere)
AActor* P1;
UPROPERTY(EditAnywhere)
AActor* P2;
};

View File

@ -21,14 +21,6 @@ class KOFFOREVER_API AKOFBaseCharacter : public APaperCharacter
{
GENERATED_BODY()
/** Side view camera */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera, meta=(AllowPrivateAccess="true"))
class UCameraComponent* SideViewCameraComponent;
/** Camera boom positioning the camera beside the character */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* CameraBoom;
UTextRenderComponent* TextComponent;
virtual void Tick(float DeltaSeconds) override;
@ -74,10 +66,5 @@ protected:
public:
AKOFBaseCharacter();
/** Returns SideViewCameraComponent subobject **/
FORCEINLINE class UCameraComponent* GetSideViewCameraComponent() const { return SideViewCameraComponent; }
/** Returns CameraBoom subobject **/
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
FORCEINLINE class UPaperFlipbookComponent* GetShadow() const { return Shadow; }
};