2025-10-14 22:20:59 -04:00
|
|
|
// Copyright Echo Devgroup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "Player/AuraPlayerController.h"
|
|
|
|
|
#include "EnhancedInputSubsystems.h"
|
|
|
|
|
#include "EnhancedInputComponent.h"
|
|
|
|
|
#include "Interact/EnemyInterface.h"
|
|
|
|
|
|
|
|
|
|
AAuraPlayerController::AAuraPlayerController()
|
|
|
|
|
{
|
|
|
|
|
bReplicates = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AAuraPlayerController::PlayerTick(float DeltaTime)
|
|
|
|
|
{
|
|
|
|
|
Super::PlayerTick(DeltaTime);
|
|
|
|
|
|
|
|
|
|
CursorTrace();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AAuraPlayerController::CursorTrace()
|
|
|
|
|
{
|
|
|
|
|
FHitResult CursorHit;
|
|
|
|
|
GetHitResultUnderCursor(ECC_Visibility, false, CursorHit);
|
|
|
|
|
if (!CursorHit.bBlockingHit) return;
|
2025-10-14 23:45:02 -04:00
|
|
|
AActor* HitActor = CursorHit.GetActor();
|
|
|
|
|
IEnemyInterface* Enemy = Cast<IEnemyInterface>(HitActor);
|
2025-10-14 22:20:59 -04:00
|
|
|
|
|
|
|
|
LastActor = ThisActor;
|
2025-10-14 23:45:02 -04:00
|
|
|
ThisActor = Enemy;
|
2025-10-14 22:20:59 -04:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*Line trace from curso. There are several scenarios
|
|
|
|
|
* A. LastActor is null && ThisActor is null
|
|
|
|
|
* - Do nothing
|
|
|
|
|
* B. LastActor is null && ThisActor is valid
|
|
|
|
|
* - Highlight ThisActor
|
|
|
|
|
* C. LastActor is valid && ThisActor is null
|
|
|
|
|
* - UnHighlight LastActor
|
|
|
|
|
* D. LastAcrot is valid && ThisActor is valid but not equal
|
|
|
|
|
* - UnHighligh LastActor
|
|
|
|
|
* - Highlight ThisActor
|
|
|
|
|
* E. LastActor is same as ThisActor
|
|
|
|
|
* - Do Nothing
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (LastActor == nullptr)
|
|
|
|
|
{
|
|
|
|
|
if (ThisActor != nullptr)
|
|
|
|
|
{
|
|
|
|
|
//Case B
|
2025-10-14 23:45:02 -04:00
|
|
|
//ThisActor->HighlightActor();
|
2025-10-14 22:20:59 -04:00
|
|
|
//UE_LOG(LogTemp, Warning, TEXT("Case B"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else //LastActor is Valid
|
|
|
|
|
{
|
|
|
|
|
if (ThisActor == nullptr)
|
|
|
|
|
{
|
2025-10-14 23:45:02 -04:00
|
|
|
//LastActor->UnHighlightActor();
|
2025-10-14 22:20:59 -04:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (LastActor != ThisActor) // Case D
|
|
|
|
|
{
|
2025-10-14 23:45:02 -04:00
|
|
|
//LastActor->UnHighlightActor();
|
|
|
|
|
//ThisActor->HighlightActor();
|
2025-10-14 22:20:59 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-14 23:45:02 -04:00
|
|
|
/* //cheated and skipped ahead to try and fix error :(
|
|
|
|
|
void AAuraPlayerController::HightlightActor(AActor* Actor)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AAuraPlayerController::UnHightlightActor(AActor* Actor)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
2025-10-14 22:20:59 -04:00
|
|
|
void AAuraPlayerController::BeginPlay()
|
|
|
|
|
{
|
|
|
|
|
Super::BeginPlay();
|
|
|
|
|
check(AuraContext);
|
|
|
|
|
|
|
|
|
|
UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(GetLocalPlayer());
|
|
|
|
|
if (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);
|
|
|
|
|
|
|
|
|
|
if (APawn* ControlledPawn = GetPawn<APawn>())
|
|
|
|
|
{
|
|
|
|
|
ControlledPawn->AddMovementInput(ForwardDirection, InputAxisVector.Y);
|
|
|
|
|
ControlledPawn->AddMovementInput(RightDirection, InputAxisVector.X);
|
|
|
|
|
}
|
|
|
|
|
}
|