Convert third person template to 2D platformer
This commit is contained in:
parent
fd0988654e
commit
f7a263d2c2
BIN
GravityStomp/Content/Characters/BP_GSCharacter.uasset
(Stored with Git LFS)
BIN
GravityStomp/Content/Characters/BP_GSCharacter.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
GravityStomp/Content/Input/Actions/IA_Jump.uasset
(Stored with Git LFS)
BIN
GravityStomp/Content/Input/Actions/IA_Jump.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
GravityStomp/Content/Input/Actions/IA_Look.uasset
(Stored with Git LFS)
BIN
GravityStomp/Content/Input/Actions/IA_Look.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
GravityStomp/Content/Input/IMC_Default.uasset
(Stored with Git LFS)
BIN
GravityStomp/Content/Input/IMC_Default.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
GravityStomp/Content/Maps/Debug/Test.umap
(Stored with Git LFS)
BIN
GravityStomp/Content/Maps/Debug/Test.umap
(Stored with Git LFS)
Binary file not shown.
@ -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<USpringArmComponent>(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<UCameraComponent>(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<UEnhancedInputComponent>(PlayerInputComponent)) {
|
||||
|
||||
//Jumping
|
||||
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump);
|
||||
EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Completed, this, &ACharacter::StopJumping);
|
||||
|
||||
if (UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(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<FVector2D>();
|
||||
|
||||
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<FVector2D>();
|
||||
|
||||
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);
|
||||
}
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user