diff --git a/Content/Blueprints/Character/GoblinSlingshot/BP_GoblinSlingshot.uasset b/Content/Blueprints/Character/GoblinSlingshot/BP_GoblinSlingshot.uasset index 72f857a..3f980ac 100644 Binary files a/Content/Blueprints/Character/GoblinSlingshot/BP_GoblinSlingshot.uasset and b/Content/Blueprints/Character/GoblinSlingshot/BP_GoblinSlingshot.uasset differ diff --git a/Content/Blueprints/Character/GoblinSpear/BP_GoblinSpear.uasset b/Content/Blueprints/Character/GoblinSpear/BP_GoblinSpear.uasset index be95b57..78c8faa 100644 Binary files a/Content/Blueprints/Character/GoblinSpear/BP_GoblinSpear.uasset and b/Content/Blueprints/Character/GoblinSpear/BP_GoblinSpear.uasset differ diff --git a/Content/Maps/StartupMap.umap b/Content/Maps/StartupMap.umap index 5f7a7c9..79c845b 100644 Binary files a/Content/Maps/StartupMap.umap and b/Content/Maps/StartupMap.umap differ diff --git a/Source/Aura/Private/Character/AuraEnemy.cpp b/Source/Aura/Private/Character/AuraEnemy.cpp index 5b0312c..fc2430c 100644 --- a/Source/Aura/Private/Character/AuraEnemy.cpp +++ b/Source/Aura/Private/Character/AuraEnemy.cpp @@ -5,8 +5,10 @@ void AAuraEnemy::HighlightActor() { + bHighlighted = true; } void AAuraEnemy::UnHighlightActor() { + bHighlighted = false; } diff --git a/Source/Aura/Private/Player/AuraPlayerController.cpp b/Source/Aura/Private/Player/AuraPlayerController.cpp index 7fb7c9d..5ab8825 100644 --- a/Source/Aura/Private/Player/AuraPlayerController.cpp +++ b/Source/Aura/Private/Player/AuraPlayerController.cpp @@ -5,12 +5,75 @@ #include "EnhancedInputSubsystems.h" #include "EnhancedInputComponent.h" +#include "Interaction/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; + + LastActor = ThisActor; + ThisActor = CursorHit.GetActor(); + + /* + * Line tracer from cursor. 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. Both actors are valid, but LastActor != ThisActor + * - UnHighlight LastActor. + * - Highlight ThisActor. + * E. Both actors are valid, and are the same actor + * - Do nothing. + */ + + if (!LastActor) + { + if (ThisActor) + { + // Case B + ThisActor->HighlightActor(); + } + // else Case A + } + else // LastActor is valid + { + if (!ThisActor) + { + // Case C + LastActor->UnHighlightActor(); + } + else + { + // Both Actors are valid + if (LastActor != ThisActor) + { + // Case D + LastActor->UnHighlightActor(); + ThisActor->HighlightActor(); + } + // else do nothing + } + } +} + void AAuraPlayerController::BeginPlay() { Super::BeginPlay(); @@ -52,4 +115,4 @@ void AAuraPlayerController::Move(const FInputActionValue& InputActionValue) ControlledPawn->AddMovementInput(ForwardDirection, InputAxisVector.Y); ControlledPawn->AddMovementInput(RightDirection, InputAxisVector.X); -} +} \ No newline at end of file diff --git a/Source/Aura/Public/Character/AuraEnemy.h b/Source/Aura/Public/Character/AuraEnemy.h index 6aaf531..24ec967 100644 --- a/Source/Aura/Public/Character/AuraEnemy.h +++ b/Source/Aura/Public/Character/AuraEnemy.h @@ -18,4 +18,7 @@ class AURA_API AAuraEnemy : public AAuraCharacterBase, public IEnemyInterface public: virtual void HighlightActor() override; virtual void UnHighlightActor() override; + + UPROPERTY (BlueprintReadOnly) + bool bHighlighted = false; }; diff --git a/Source/Aura/Public/Player/AuraPlayerController.h b/Source/Aura/Public/Player/AuraPlayerController.h index 87219f5..d745deb 100644 --- a/Source/Aura/Public/Player/AuraPlayerController.h +++ b/Source/Aura/Public/Player/AuraPlayerController.h @@ -9,6 +9,8 @@ class UInputMappingContext; class UInputAction; +class IEnemyInterface; + struct FInputActionValue; UCLASS() @@ -18,6 +20,7 @@ class AURA_API AAuraPlayerController : public APlayerController public: AAuraPlayerController (); + virtual void PlayerTick(float DeltaTime) override; protected: virtual void BeginPlay() override; @@ -31,4 +34,10 @@ private: TObjectPtr MoveAction; void Move (const FInputActionValue &InputActionValue); + + void CursorTrace (); + + // for highlighting + TScriptInterface LastActor; // TScriptInterface must be used to hold interfaces + TScriptInterface ThisActor; };