enhanced input and movement logic
This commit is contained in:
parent
c69563f6a3
commit
bcf4af827c
BIN
Content/Blueprints/Input/IMC_AuraContext.uasset
Normal file
BIN
Content/Blueprints/Input/IMC_AuraContext.uasset
Normal file
Binary file not shown.
BIN
Content/Blueprints/Input/InputActions/IA_Move.uasset
Normal file
BIN
Content/Blueprints/Input/InputActions/IA_Move.uasset
Normal file
Binary file not shown.
BIN
Content/Blueprints/Player/BP_AuraPlayerController.uasset
Normal file
BIN
Content/Blueprints/Player/BP_AuraPlayerController.uasset
Normal file
Binary file not shown.
@ -8,7 +8,7 @@ public class Aura : ModuleRules
|
||||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput" });
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
|
||||
|
55
Source/Aura/Private/Player/AuraPlayerController.cpp
Normal file
55
Source/Aura/Private/Player/AuraPlayerController.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
// Copyright; GhostPacket Games
|
||||
|
||||
|
||||
#include "Player/AuraPlayerController.h"
|
||||
|
||||
#include "EnhancedInputSubsystems.h"
|
||||
#include "EnhancedInputComponent.h"
|
||||
|
||||
AAuraPlayerController::AAuraPlayerController()
|
||||
{
|
||||
bReplicates = true;
|
||||
}
|
||||
|
||||
void AAuraPlayerController::BeginPlay()
|
||||
{
|
||||
Super::BeginPlay();
|
||||
check(AuraContext); // checks it's set
|
||||
|
||||
UEnhancedInputLocalPlayerSubsystem *Subsystem = ULocalPlayer::GetSubsystem <UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer ());
|
||||
check (Subsystem);
|
||||
Subsystem->AddMappingContext (AuraContext, 0);
|
||||
|
||||
bShowMouseCursor = true;
|
||||
DefaultMouseCursor = EMouseCursor::Default;
|
||||
|
||||
FInputModeGameAndUI InputModeData;
|
||||
InputModeData.SetLockMouseToViewportBehavior(EMouseLockMode::DoNotLock);
|
||||
InputModeData.SetHideCursorDuringCapture(false);
|
||||
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);
|
||||
|
||||
APawn *ControlledPawn = GetPawn<APawn>();
|
||||
if (!ControlledPawn)
|
||||
return;
|
||||
|
||||
ControlledPawn->AddMovementInput(ForwardDirection, InputAxisVector.Y);
|
||||
ControlledPawn->AddMovementInput(RightDirection, InputAxisVector.X);
|
||||
}
|
34
Source/Aura/Public/Player/AuraPlayerController.h
Normal file
34
Source/Aura/Public/Player/AuraPlayerController.h
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright; GhostPacket Games
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "AuraPlayerController.generated.h"
|
||||
|
||||
class UInputMappingContext;
|
||||
class UInputAction;
|
||||
|
||||
struct FInputActionValue;
|
||||
|
||||
UCLASS()
|
||||
class AURA_API AAuraPlayerController : public APlayerController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
AAuraPlayerController ();
|
||||
|
||||
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);
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user