From 6e0c1810145dd5434e5357ce61504dd21c7f9e4a Mon Sep 17 00:00:00 2001 From: Kevin Date: Sat, 15 Jan 2022 19:19:22 -0500 Subject: [PATCH] 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 --- .gitignore | 1 + .../Content/Core/BP_DefaultCamera.uasset | 3 + KOFForever/Content/Maps/TestMap.umap | 4 +- KOFForever/KOFForever.uproject | 3 +- .../Private/Camera/KOFDefaultCamera.cpp | 36 ++++++++++++ .../Private/Character/KOFBaseCharacter.cpp | 17 ------ .../Public/Camera/KOFDefaultCamera.h | 56 +++++++++++++++++++ .../Public/Character/KOFBaseCharacter.h | 13 ----- 8 files changed, 100 insertions(+), 33 deletions(-) create mode 100644 KOFForever/Content/Core/BP_DefaultCamera.uasset create mode 100644 KOFForever/Source/KOFForever/Private/Camera/KOFDefaultCamera.cpp create mode 100644 KOFForever/Source/KOFForever/Public/Camera/KOFDefaultCamera.h diff --git a/.gitignore b/.gitignore index 839866f..9111197 100644 --- a/.gitignore +++ b/.gitignore @@ -68,3 +68,4 @@ Build/*/** # Cache files for the editor to use **/DerivedDataCache/* +Scratch diff --git a/KOFForever/Content/Core/BP_DefaultCamera.uasset b/KOFForever/Content/Core/BP_DefaultCamera.uasset new file mode 100644 index 0000000..c408c80 --- /dev/null +++ b/KOFForever/Content/Core/BP_DefaultCamera.uasset @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b6e1ed4c6c619bc2c8705abd07d29328d8d0400e48497b1e96256d9cf2842e94 +size 20151 diff --git a/KOFForever/Content/Maps/TestMap.umap b/KOFForever/Content/Maps/TestMap.umap index c2069a2..4c4cd3f 100644 --- a/KOFForever/Content/Maps/TestMap.umap +++ b/KOFForever/Content/Maps/TestMap.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:65d157090f0f3aaa5437271f4b057f8cdc3903780bd72c0a461a303c6c7cb337 -size 8538726 +oid sha256:4b072fd78e49c25d512dc5058eaebf9320b15d8e49f6ae77ef409ce1ef92f219 +size 8537801 diff --git a/KOFForever/KOFForever.uproject b/KOFForever/KOFForever.uproject index 3e9a18f..f41e767 100644 --- a/KOFForever/KOFForever.uproject +++ b/KOFForever/KOFForever.uproject @@ -9,7 +9,8 @@ "Type": "Runtime", "LoadingPhase": "Default", "AdditionalDependencies": [ - "Paper2D" + "Paper2D", + "Engine" ] } ] diff --git a/KOFForever/Source/KOFForever/Private/Camera/KOFDefaultCamera.cpp b/KOFForever/Source/KOFForever/Private/Camera/KOFDefaultCamera.cpp new file mode 100644 index 0000000..f2af1db --- /dev/null +++ b/KOFForever/Source/KOFForever/Private/Camera/KOFDefaultCamera.cpp @@ -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 +} diff --git a/KOFForever/Source/KOFForever/Private/Character/KOFBaseCharacter.cpp b/KOFForever/Source/KOFForever/Private/Character/KOFBaseCharacter.cpp index 39eff95..b3d384a 100644 --- a/KOFForever/Source/KOFForever/Private/Character/KOFBaseCharacter.cpp +++ b/KOFForever/Source/KOFForever/Private/Character/KOFBaseCharacter.cpp @@ -24,24 +24,7 @@ AKOFBaseCharacter::AKOFBaseCharacter() // Set the size of our collision capsule. GetCapsuleComponent()->SetCapsuleHalfHeight(96.0f); GetCapsuleComponent()->SetCapsuleRadius(40.0f); - - // Create a camera boom attached to the root (capsule) - CameraBoom = CreateDefaultSubobject(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(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 diff --git a/KOFForever/Source/KOFForever/Public/Camera/KOFDefaultCamera.h b/KOFForever/Source/KOFForever/Public/Camera/KOFDefaultCamera.h new file mode 100644 index 0000000..1a48a6c --- /dev/null +++ b/KOFForever/Source/KOFForever/Public/Camera/KOFDefaultCamera.h @@ -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; +}; diff --git a/KOFForever/Source/KOFForever/Public/Character/KOFBaseCharacter.h b/KOFForever/Source/KOFForever/Public/Character/KOFBaseCharacter.h index 626b4ac..e9f7099 100644 --- a/KOFForever/Source/KOFForever/Public/Character/KOFBaseCharacter.h +++ b/KOFForever/Source/KOFForever/Public/Character/KOFBaseCharacter.h @@ -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; } };