Game Mode, Camera
This commit is contained in:
parent
6e06627910
commit
99a3e46635
3
.gitignore
vendored
3
.gitignore
vendored
@ -15,3 +15,6 @@ Project/.vsconfig
|
|||||||
*.target
|
*.target
|
||||||
*.modules
|
*.modules
|
||||||
Project/.idea
|
Project/.idea
|
||||||
|
|
||||||
|
Project/Saved/Screenshots
|
||||||
|
*/Binaries/Win64/*.patch_*.*
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3,6 +3,7 @@
|
|||||||
[/Script/EngineSettings.GameMapsSettings]
|
[/Script/EngineSettings.GameMapsSettings]
|
||||||
GameDefaultMap=/Game/Levels/StartupMap.StartupMap
|
GameDefaultMap=/Game/Levels/StartupMap.StartupMap
|
||||||
EditorStartupMap=/Game/Levels/StartupMap.StartupMap
|
EditorStartupMap=/Game/Levels/StartupMap.StartupMap
|
||||||
|
GlobalDefaultGameMode=/Game/Core/Game/BP_GameMode.BP_GameMode_C
|
||||||
|
|
||||||
[/Script/WindowsTargetPlatform.WindowsTargetSettings]
|
[/Script/WindowsTargetPlatform.WindowsTargetSettings]
|
||||||
DefaultGraphicsRHI=DefaultGraphicsRHI_DX12
|
DefaultGraphicsRHI=DefaultGraphicsRHI_DX12
|
||||||
|
BIN
Project/Content/Core/Actors/ABP_PlayerCharacter.uasset
(Stored with Git LFS)
BIN
Project/Content/Core/Actors/ABP_PlayerCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Project/Content/Core/Actors/BP_PlayerCharacter.uasset
(Stored with Git LFS)
BIN
Project/Content/Core/Actors/BP_PlayerCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Project/Content/Core/Game/BP_GameMode.uasset
(Stored with Git LFS)
Normal file
BIN
Project/Content/Core/Game/BP_GameMode.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
Project/Content/Levels/StartupMap.umap
(Stored with Git LFS)
BIN
Project/Content/Levels/StartupMap.umap
(Stored with Git LFS)
Binary file not shown.
@ -1,11 +1,41 @@
|
|||||||
#include "GasaCharacter.h"
|
#include "GasaCharacter.h"
|
||||||
|
|
||||||
|
#include "Camera/CameraComponent.h"
|
||||||
|
#include "GameFramework/CharacterMovementComponent.h"
|
||||||
|
#include "GameFramework/SpringArmComponent.h"
|
||||||
|
|
||||||
AGasaCharacter::AGasaCharacter()
|
AGasaCharacter::AGasaCharacter()
|
||||||
{
|
{
|
||||||
PrimaryActorTick.bCanEverTick = false;
|
PrimaryActorTick.bCanEverTick = false;
|
||||||
|
|
||||||
|
UCharacterMovementComponent*
|
||||||
|
Movement = GetCharacterMovement();
|
||||||
|
Movement->bOrientRotationToMovement = true;
|
||||||
|
Movement->bConstrainToPlane = true;
|
||||||
|
Movement->bSnapToPlaneAtStart = true;
|
||||||
|
Movement->RotationRate = FRotator(0.0, 400.f, 0.0);
|
||||||
|
|
||||||
|
bUseControllerRotationPitch = false;
|
||||||
|
bUseControllerRotationRoll = false;
|
||||||
|
bUseControllerRotationYaw = false;
|
||||||
|
|
||||||
|
USceneComponent* root_component = GetRootComponent();
|
||||||
|
USkeletalMeshComponent* mesh = GetMesh();
|
||||||
|
|
||||||
|
CamSpringArm = CreateDefaultSubobject<USpringArmComponent>("Camera Spring Arm");
|
||||||
|
CamSpringArm->SetupAttachment(root_component);
|
||||||
|
CamSpringArm->SetRelativeRotation( FQuat::MakeFromEuler(FVector(0.0, -35.0, 0.0)));
|
||||||
|
CamSpringArm->TargetArmLength = 400.0f;
|
||||||
|
|
||||||
|
CamSpringArm->bInheritPitch = false;
|
||||||
|
CamSpringArm->bInheritYaw = false;
|
||||||
|
CamSpringArm->bInheritRoll = false;
|
||||||
|
|
||||||
|
Camera = CreateDefaultSubobject<UCameraComponent>("Camera");
|
||||||
|
Camera->SetupAttachment(CamSpringArm);
|
||||||
|
|
||||||
Weapon = CreateDefaultSubobject<USkeletalMeshComponent>("Weapon");
|
Weapon = CreateDefaultSubobject<USkeletalMeshComponent>("Weapon");
|
||||||
Weapon->SetupAttachment(GetMesh(), FName("WeaponAttach"));
|
Weapon->SetupAttachment(mesh, FName("WeaponAttach"));
|
||||||
Weapon->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
Weapon->SetCollisionEnabled(ECollisionEnabled::NoCollision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "GasaCommon.h"
|
||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
|
|
||||||
#include "GasaCharacter.generated.h"
|
#include "GasaCharacter.generated.h"
|
||||||
@ -9,6 +10,14 @@ class GASA_API AGasaCharacter : public ACharacter
|
|||||||
{
|
{
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
public:
|
public:
|
||||||
|
#pragma region Camera
|
||||||
|
UPROPERTY(EditAnywhere, Category="Camera")
|
||||||
|
UCameraComponent* Camera;
|
||||||
|
|
||||||
|
UPROPERTY(EditAnywhere, Category="Camera")
|
||||||
|
USpringArmComponent* CamSpringArm;
|
||||||
|
#pragma endregion Camera
|
||||||
|
|
||||||
#pragma region Combat
|
#pragma region Combat
|
||||||
UPROPERTY(EditAnywhere, Category="Combat")
|
UPROPERTY(EditAnywhere, Category="Combat")
|
||||||
TObjectPtr<USkeletalMeshComponent> Weapon;
|
TObjectPtr<USkeletalMeshComponent> Weapon;
|
||||||
|
@ -55,6 +55,6 @@ public class Gasa : ModuleRules
|
|||||||
}
|
}
|
||||||
#endregion Plugins
|
#endregion Plugins
|
||||||
|
|
||||||
PublicIncludePathModuleNames.Add("Gasa");
|
PublicIncludePaths.Add("Gasa");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
// #define private protected
|
// #define private protected
|
||||||
|
|
||||||
|
class UCameraComponent;
|
||||||
class UInputAction;
|
class UInputAction;
|
||||||
struct FInputActionValue;
|
struct FInputActionValue;
|
||||||
class UInputMappingContext;
|
class UInputMappingContext;
|
||||||
|
class USpringArmComponent;
|
||||||
|
2
Project/Source/Gasa/GasaGameMode.cpp
Normal file
2
Project/Source/Gasa/GasaGameMode.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#include "GasaGameMode.h"
|
||||||
|
|
11
Project/Source/Gasa/GasaGameMode.h
Normal file
11
Project/Source/Gasa/GasaGameMode.h
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "GameFramework/GameMode.h"
|
||||||
|
|
||||||
|
#include "GasaGameMode.generated.h"
|
||||||
|
|
||||||
|
UCLASS(Blueprintable)
|
||||||
|
class GASA_API AGasaGameMode : public AGameMode
|
||||||
|
{
|
||||||
|
GENERATED_BODY()
|
||||||
|
public:
|
||||||
|
};
|
@ -11,6 +11,11 @@ AGasaPlayerController::AGasaPlayerController()
|
|||||||
|
|
||||||
void AGasaPlayerController::Move(FInputActionValue const& ActionValue)
|
void AGasaPlayerController::Move(FInputActionValue const& ActionValue)
|
||||||
{
|
{
|
||||||
|
APawn* pawn = GetPawn<APawn>();
|
||||||
|
if (pawn == nullptr )
|
||||||
|
return;
|
||||||
|
|
||||||
|
// Note(Ed): I did the follow optimization for practice, they are completely unnecessary for this context.
|
||||||
#if 0
|
#if 0
|
||||||
FVector2D AxisV = ActionValue.Get<FVector2D>();
|
FVector2D AxisV = ActionValue.Get<FVector2D>();
|
||||||
FRotator ControlRot = GetControlRotation();
|
FRotator ControlRot = GetControlRotation();
|
||||||
@ -19,31 +24,31 @@ void AGasaPlayerController::Move(FInputActionValue const& ActionValue)
|
|||||||
FVector FwdDir = FRotationMatrix(YawRot).GetUnitAxis(EAxis::X);
|
FVector FwdDir = FRotationMatrix(YawRot).GetUnitAxis(EAxis::X);
|
||||||
FVector RightDir = FRotationMatrix(YawRot).GetUnitAxis(EAxis::Y);
|
FVector RightDir = FRotationMatrix(YawRot).GetUnitAxis(EAxis::Y);
|
||||||
|
|
||||||
APawn* Pawn = GetPawn<APawn>();
|
PPawn->AddMovementInput(FwdDir, AxisV.Y);
|
||||||
if (Pawn)
|
PPawn->AddMovementInput(RightDir, AxisV.X);
|
||||||
{
|
|
||||||
Pawn->AddMovementInput(FwdDir, AxisV.Y);
|
|
||||||
Pawn->AddMovementInput(RightDir, AxisV.X);
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
FVector2f AxisV = FVector2f(ActionValue.Get<FVector2D>());
|
FVector2f AxisV = FVector2f(ActionValue.Get<FVector2D>());
|
||||||
FQuat // FQuat isomorphic to FRotor (Hypothetical Def)
|
|
||||||
ControlRotor = GetControlRotation().Quaternion();
|
FQuat4f // FQuat isomorphic to FRotor (Hypothetical Def)
|
||||||
|
ControlRotor = FQuat4f(GetControlRotation().Quaternion());
|
||||||
// ControlRotor.Normalize(); // The Quaternion should always be a versor with UE...
|
// ControlRotor.Normalize(); // The Quaternion should always be a versor with UE...
|
||||||
|
|
||||||
FQuat4f
|
FVector3f HorizontalForward = ControlRotor.RotateVector(FVector3f::ForwardVector);
|
||||||
YawRotor = FQuat4f(FVector3f::UpVector, ControlRotor.GetAngle());
|
// HorizontalForward.Normalize();
|
||||||
|
|
||||||
|
// TODO(Ed): Profile which is faster just to know... (atan2 vs FindBetweenVectors)
|
||||||
|
// HorizontalForward.Z = 0;
|
||||||
|
// FQuat4f
|
||||||
|
// YawRotor = FQuat4f::FindBetweenVectors(FVector3f::ForwardVector, HorizontalForward);
|
||||||
// YawRotor.Normalize(); // The Quaternion should always be a versor with UE...
|
// YawRotor.Normalize(); // The Quaternion should always be a versor with UE...
|
||||||
|
|
||||||
FVector3f FwdDir = YawRotor.RotateVector(FVector3f::ForwardVector);
|
// Need only one axis of rotation so this might be a possible optimization
|
||||||
FVector3f RightDir = YawRotor.RotateVector(FVector3f::RightVector);
|
float YawAngle = FMath::Atan2(HorizontalForward.Y, HorizontalForward.X);
|
||||||
|
FQuat4f YawRotor = FQuat4f(FVector3f::UpVector, YawAngle);
|
||||||
|
|
||||||
APawn* PPawn = GetPawn<APawn>();
|
// Rotate the combined input by the yaw rotor to get the movement direction
|
||||||
if (PPawn)
|
FVector MoveDir = (FVector) YawRotor.RotateVector( FVector3f(AxisV.Y, AxisV.X, 0.f));
|
||||||
{
|
pawn->AddMovementInput( MoveDir );
|
||||||
PPawn->AddMovementInput(FVector(FwdDir), AxisV.Y);
|
|
||||||
PPawn->AddMovementInput(FVector(RightDir), AxisV.X);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user