Movement Input

This commit is contained in:
2024-11-17 20:23:54 -04:00
parent 33f5971de1
commit 43650f25cb
3 changed files with 37 additions and 0 deletions

BIN
Content/Blueprints/Player/BP_AuraPlayerController.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -3,6 +3,7 @@
#include "Player/AuraPlayerController.h" #include "Player/AuraPlayerController.h"
#include "EnhancedInputSubsystems.h" #include "EnhancedInputSubsystems.h"
#include "EnhancedInputComponent.h"
AAuraPlayerController::AAuraPlayerController() AAuraPlayerController::AAuraPlayerController()
{ {
@ -27,3 +28,27 @@ void AAuraPlayerController::BeginPlay()
SetInputMode(InputModeData); SetInputMode(InputModeData);
} }
void AAuraPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
UEnhancedInputComponent* EnhancedInputComponent = CastChecked<UEnhancedInputComponent>(InputComponent);
EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AAuraPlayerController::Move);
}
void AAuraPlayerController::Move(const FInputActionValue& InputActionValue)
{
const FVector2D InputAxisVector = InputActionValue.Get<FVector2D>();
const FRotator Rotation = GetControlRotation();
const FRotator YawRotation(0.f, Rotation.Yaw, 0.f);
const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
if (APawn* ControlledPawn = GetPawn<APawn>())
{
ControlledPawn->AddMovementInput(ForwardDirection, InputAxisVector.Y);
ControlledPawn->AddMovementInput(RightDirection, InputAxisVector.X);
}
}

View File

@ -6,6 +6,8 @@
#include "GameFramework/PlayerController.h" #include "GameFramework/PlayerController.h"
#include "AuraPlayerController.generated.h" #include "AuraPlayerController.generated.h"
struct FInputActionValue;
class UInputAction;
class UInputMappingContext; class UInputMappingContext;
/** /**
@ -22,7 +24,14 @@ public:
protected: protected:
virtual void BeginPlay() override; virtual void BeginPlay() override;
virtual void SetupInputComponent() override;
private: private:
UPROPERTY(EditAnywhere, Category="Input") UPROPERTY(EditAnywhere, Category="Input")
TObjectPtr<UInputMappingContext> AuraContext; TObjectPtr<UInputMappingContext> AuraContext;
UPROPERTY(EditAnywhere, Category="Input")
TObjectPtr<UInputAction> MoveAction;
void Move(const FInputActionValue& InputActionValue);
}; };