From f7a263d2c2ceba85ad09188d1d49c36f2935d863 Mon Sep 17 00:00:00 2001 From: Kevin Poretti Date: Tue, 3 Jan 2023 17:56:24 -0500 Subject: [PATCH] Convert third person template to 2D platformer --- .../Content/Characters/BP_GSCharacter.uasset | 4 +- .../Content/Input/Actions/IA_Jump.uasset | 3 - .../Content/Input/Actions/IA_Look.uasset | 3 - GravityStomp/Content/Input/IMC_Default.uasset | 4 +- GravityStomp/Content/Maps/Debug/Test.umap | 4 +- .../Character/GSCharacter.cpp | 57 ++++--------------- .../GravityStompGame/Character/GSCharacter.h | 15 +---- 7 files changed, 19 insertions(+), 71 deletions(-) delete mode 100644 GravityStomp/Content/Input/Actions/IA_Jump.uasset delete mode 100644 GravityStomp/Content/Input/Actions/IA_Look.uasset diff --git a/GravityStomp/Content/Characters/BP_GSCharacter.uasset b/GravityStomp/Content/Characters/BP_GSCharacter.uasset index 25002ba..d8a5c90 100644 --- a/GravityStomp/Content/Characters/BP_GSCharacter.uasset +++ b/GravityStomp/Content/Characters/BP_GSCharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:87813b7d80d2d3943cc079ca67a0db48dec31b6ab53d8a267c8ba0c055b37a35 -size 33675 +oid sha256:1d3a6e67f2471cbe40d48d70ed4503d295a06dbe392934d846086b1738822947 +size 33811 diff --git a/GravityStomp/Content/Input/Actions/IA_Jump.uasset b/GravityStomp/Content/Input/Actions/IA_Jump.uasset deleted file mode 100644 index de4374d..0000000 --- a/GravityStomp/Content/Input/Actions/IA_Jump.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ae9b280709f3d320fcaee33c24aa6ec6ca99d382021e167770c9308fad13dc86 -size 1326 diff --git a/GravityStomp/Content/Input/Actions/IA_Look.uasset b/GravityStomp/Content/Input/Actions/IA_Look.uasset deleted file mode 100644 index 48052fc..0000000 --- a/GravityStomp/Content/Input/Actions/IA_Look.uasset +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:1afd704659e3f963866ae8d82bc1f76d86563fbf16f242e40526b15120cae06b -size 1473 diff --git a/GravityStomp/Content/Input/IMC_Default.uasset b/GravityStomp/Content/Input/IMC_Default.uasset index fea1698..6adf69b 100644 --- a/GravityStomp/Content/Input/IMC_Default.uasset +++ b/GravityStomp/Content/Input/IMC_Default.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:f35ba8cda4e87d7072a67d008e81991ce49772a91ff2b46fe0bf2b5361796633 -size 12601 +oid sha256:752bf0509c42fa9b42f3482eee83cc08fe27fa5a75f775925b11a0e1879cb775 +size 9160 diff --git a/GravityStomp/Content/Maps/Debug/Test.umap b/GravityStomp/Content/Maps/Debug/Test.umap index a1ede27..5e77e93 100644 --- a/GravityStomp/Content/Maps/Debug/Test.umap +++ b/GravityStomp/Content/Maps/Debug/Test.umap @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:c6ffb7193a4781b63472d76ceaaa93932e8890e78aa671054fcdf9a9246a1f1c -size 37837 +oid sha256:ee4e84afccfef473907467c031698133fc1a7055160d75d324db3b82604185f7 +size 47476 diff --git a/GravityStomp/Source/GravityStompGame/Character/GSCharacter.cpp b/GravityStomp/Source/GravityStompGame/Character/GSCharacter.cpp index cc4d2e9..153f794 100644 --- a/GravityStomp/Source/GravityStompGame/Character/GSCharacter.cpp +++ b/GravityStomp/Source/GravityStompGame/Character/GSCharacter.cpp @@ -9,6 +9,7 @@ #include "GameFramework/SpringArmComponent.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" +#include "Kismet/KismetMathLibrary.h" ////////////////////////////////////////////////////////////////////////// @@ -40,7 +41,9 @@ AGSCharacter::AGSCharacter() CameraBoom = CreateDefaultSubobject(TEXT("CameraBoom")); CameraBoom->SetupAttachment(RootComponent); CameraBoom->TargetArmLength = 400.0f; // The camera follows at this distance behind the character - CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller + CameraBoom->bUsePawnControlRotation = false; // Rotate the arm based on the controller + + CameraBoom->SetWorldRotation(FVector::ForwardVector.Rotation()); // Create a follow camera FollowCamera = CreateDefaultSubobject(TEXT("FollowCamera")); @@ -51,6 +54,7 @@ AGSCharacter::AGSCharacter() // are set in the derived blueprint asset named ThirdPersonCharacter (to avoid direct content references in C++) } + void AGSCharacter::BeginPlay() { // Call the base class @@ -72,58 +76,21 @@ void AGSCharacter::BeginPlay() void AGSCharacter::SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) { // Set up action bindings - if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked(PlayerInputComponent)) { - - //Jumping - EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump); - EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping); - + if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked(PlayerInputComponent)) + { //Moving EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AGSCharacter::Move); - - //Looking - EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AGSCharacter::Look); - } } + void AGSCharacter::Move(const FInputActionValue& Value) { // input is a Vector2D FVector2D MovementVector = Value.Get(); - if (Controller != nullptr) - { - // find out which way is forward - const FRotator Rotation = Controller->GetControlRotation(); - const FRotator YawRotation(0, Rotation.Yaw, 0); - - // get forward vector - const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); - - // get right vector - const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); - - // add movement - AddMovementInput(ForwardDirection, MovementVector.Y); - AddMovementInput(RightDirection, MovementVector.X); - } -} - -void AGSCharacter::Look(const FInputActionValue& Value) -{ - // input is a Vector2D - FVector2D LookAxisVector = Value.Get(); - - if (Controller != nullptr) - { - // add yaw and pitch input to controller - AddControllerYawInput(LookAxisVector.X); - AddControllerPitchInput(LookAxisVector.Y); - } -} - - - - + // add movement + AddMovementInput(FVector::UpVector, MovementVector.Y); + AddMovementInput(FVector::RightVector, MovementVector.X); +} \ No newline at end of file diff --git a/GravityStomp/Source/GravityStompGame/Character/GSCharacter.h b/GravityStomp/Source/GravityStompGame/Character/GSCharacter.h index 4612d40..de355a9 100644 --- a/GravityStomp/Source/GravityStompGame/Character/GSCharacter.h +++ b/GravityStomp/Source/GravityStompGame/Character/GSCharacter.h @@ -25,31 +25,18 @@ class AGSCharacter : public ACharacter UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) class UInputMappingContext* DefaultMappingContext; - /** Jump Input Action */ - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) - class UInputAction* JumpAction; - /** Move Input Action */ UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) - class UInputAction* MoveAction; - - /** Look Input Action */ - UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Input, meta = (AllowPrivateAccess = "true")) - class UInputAction* LookAction; + class UInputAction* MoveAction;; public: AGSCharacter(); - protected: /** Called for movement input */ void Move(const FInputActionValue& Value); - /** Called for looking input */ - void Look(const FInputActionValue& Value); - - protected: // APawn interface virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;