Movement Input
This commit is contained in:
BIN
Content/Blueprints/Player/BP_AuraPlayerController.uasset
(Stored with Git LFS)
Normal file
BIN
Content/Blueprints/Player/BP_AuraPlayerController.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -3,6 +3,7 @@
|
||||
|
||||
#include "Player/AuraPlayerController.h"
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
|
||||
AAuraPlayerController::AAuraPlayerController()
|
||||
{
|
||||
@ -27,3 +28,27 @@ void AAuraPlayerController::BeginPlay()
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,8 @@
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "AuraPlayerController.generated.h"
|
||||
|
||||
struct FInputActionValue;
|
||||
class UInputAction;
|
||||
class UInputMappingContext;
|
||||
|
||||
/**
|
||||
@ -22,7 +24,14 @@ public:
|
||||
protected:
|
||||
virtual void BeginPlay() override;
|
||||
|
||||
virtual void SetupInputComponent() override;
|
||||
|
||||
private:
|
||||
UPROPERTY(EditAnywhere, Category="Input")
|
||||
TObjectPtr<UInputMappingContext> AuraContext;
|
||||
|
||||
UPROPERTY(EditAnywhere, Category="Input")
|
||||
TObjectPtr<UInputAction> MoveAction;
|
||||
|
||||
void Move(const FInputActionValue& InputActionValue);
|
||||
};
|
||||
|
Reference in New Issue
Block a user