diff --git a/Content/Luprex/lxUtilityFunctionsLibrary.uasset b/Content/Luprex/lxUtilityFunctionsLibrary.uasset index cd6475f4..6c434154 100644 --- a/Content/Luprex/lxUtilityFunctionsLibrary.uasset +++ b/Content/Luprex/lxUtilityFunctionsLibrary.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:ca718d4567c103f5f26cc77994eb1bf9000dbe53bdd08c8adfa9d1b00e058cdc -size 154687 +oid sha256:2f189858227a966a70f08cf12a1e56dd569eadd85872470600e3d3cd0184a07b +size 83893 diff --git a/Content/Tangibles/tangiblecharacter.uasset b/Content/Tangibles/tangiblecharacter.uasset index 6ba81011..aaca0c2d 100644 --- a/Content/Tangibles/tangiblecharacter.uasset +++ b/Content/Tangibles/tangiblecharacter.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:da03b687409ab2440c845869e974081e8b857c6331756b43e5a5268d6a4d5f8c -size 366724 +oid sha256:77c1e7955db95535f55af2cafb864aec14c517962416776e340c4fbc2e538a60 +size 364338 diff --git a/Source/Integration/Integration.Build.cs b/Source/Integration/Integration.Build.cs index 3e3578b3..b8725aae 100644 --- a/Source/Integration/Integration.Build.cs +++ b/Source/Integration/Integration.Build.cs @@ -8,7 +8,7 @@ public class Integration : ModuleRules { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; - PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Sockets", "Networking" }); + PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Sockets", "Networking", "EnhancedInput" }); PrivateDependencyModuleNames.AddRange(new string[] { }); diff --git a/Source/Integration/UtilityLibrary.cpp b/Source/Integration/UtilityLibrary.cpp index 6a1b28ea..05a3733f 100644 --- a/Source/Integration/UtilityLibrary.cpp +++ b/Source/Integration/UtilityLibrary.cpp @@ -2,6 +2,8 @@ #include "UtilityLibrary.h" +#include "GameFramework/PlayerController.h" +#include "EnhancedInputSubsystems.h" #define LOCTEXT_NAMESPACE "Luprex Utility" @@ -60,3 +62,32 @@ FBox UlxUtilityLibrary::GetActorBounds(const AActor *target, bool bOnlyColliding return FBox::BuildAABB(ActorOrigin, BoxExtent); } + +void UlxUtilityLibrary::AddMovementInputRightward(APawn *target, double ScaleValue, bool Force) { + FRotator rotator = target->GetControlRotation(); + rotator.Pitch = 0.0; + rotator.Roll = 0.0; + rotator.Yaw += 90.0; + FVector vector = rotator.Vector(); + target->AddMovementInput(vector, ScaleValue, Force); +} + +void UlxUtilityLibrary::AddMovementInputForward(APawn *target, double ScaleValue, bool Force) { + FRotator rotator = target->GetControlRotation(); + rotator.Roll = 0.0; + rotator.Pitch = 0.0; + FVector vector = rotator.Vector(); + target->AddMovementInput(vector, ScaleValue, Force); +} + +UEnhancedInputLocalPlayerSubsystem *UlxUtilityLibrary::GetEnhancedInputLocalPlayerSubsystem(AController *Controller) { + APlayerController *pc = Cast(Controller); + if (pc != nullptr) { + UEnhancedInputLocalPlayerSubsystem* subsys = + ULocalPlayer::GetSubsystem(pc->GetLocalPlayer()); + if (subsys != nullptr) { + return subsys; + } + } + return nullptr; +} diff --git a/Source/Integration/UtilityLibrary.h b/Source/Integration/UtilityLibrary.h index 8d3dde94..f183adc7 100644 --- a/Source/Integration/UtilityLibrary.h +++ b/Source/Integration/UtilityLibrary.h @@ -5,10 +5,13 @@ #include "CoreMinimal.h" #include "UtilityLibrary.generated.h" +class UEnhancedInputLocalPlayerSubsystem; + /** * - * UlxUtilityLibrary is for functions that are just generally-useful functionality - * that Unreal includes, but for some reason was not made accessible to Blueprints. + * UlxUtilityLibrary is for functions that are aren't particularly luprex-specific, + * but rather, are just generally-useful functionality that could help in any + * Unreal program. * */ UCLASS() @@ -33,4 +36,20 @@ public: // UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Luprex|Utility") static FBox GetActorBounds(const AActor *target, bool bOnlyCollidingComponents = false, bool bIncludeFromChildActors = false); + + // Add movement input, using the yaw of the control rotation to find a rightward vector. + // + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Pawn|Input") + static void AddMovementInputRightward(APawn *target, double ScaleValue=1.0, bool Force=false); + + // Add movement input, using the yaw of the control rotation to find a forward vector. + // + UFUNCTION(BlueprintCallable, Meta = (DefaultToSelf = "target"), Category = "Pawn|Input") + static void AddMovementInputForward(APawn *target, double ScaleValue=1.0, bool Force=false); + + // Get the enhanced input local player subsystem from a controller. If the controller + // is not a player controller, or if it is a player controller but it doesn't have an + // enhanced input subsystem, return nullptr. + UFUNCTION(BlueprintCallable, BlueprintPure, Category="Player Controller|Local Player Subsystems") + static UEnhancedInputLocalPlayerSubsystem *GetEnhancedInputLocalPlayerSubsystem(AController *Controller); };