Move some utility functions from Blueprint to C++

This commit is contained in:
2024-10-15 16:17:44 -04:00
parent 25dd7cabcb
commit ecbca6e5a2
5 changed files with 57 additions and 7 deletions

View File

@@ -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<APlayerController>(Controller);
if (pc != nullptr) {
UEnhancedInputLocalPlayerSubsystem* subsys =
ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(pc->GetLocalPlayer());
if (subsys != nullptr) {
return subsys;
}
}
return nullptr;
}