enhanced input and movement logic

This commit is contained in:
Futaba Soup 2025-08-28 20:11:10 -05:00
parent c69563f6a3
commit bcf4af827c
6 changed files with 90 additions and 1 deletions

Binary file not shown.

Binary file not shown.

View File

@ -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[] { });

View 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);
}

View 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);
};