From 8339202ff4137533377456d5e024345277f9c02d Mon Sep 17 00:00:00 2001 From: martinluckyrobots Date: Mon, 14 Apr 2025 10:45:07 +0800 Subject: [PATCH] optimization BP_selectorPoi --- Source/LuckyWorldV2/LuckyWorldV2.Build.cs | 3 ++- .../Private/Gameplay/TargetSelector.cpp | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/Source/LuckyWorldV2/LuckyWorldV2.Build.cs b/Source/LuckyWorldV2/LuckyWorldV2.Build.cs index 31f654f8..7829bc2c 100644 --- a/Source/LuckyWorldV2/LuckyWorldV2.Build.cs +++ b/Source/LuckyWorldV2/LuckyWorldV2.Build.cs @@ -18,7 +18,8 @@ public class LuckyWorldV2 : ModuleRules "LuckyTextWrite", "SocketIOClient", "VaRest", - "SIOJson" + "SIOJson", + "NavigationSystem" }); PrivateDependencyModuleNames.AddRange(new string[] { }); diff --git a/Source/LuckyWorldV2/Private/Gameplay/TargetSelector.cpp b/Source/LuckyWorldV2/Private/Gameplay/TargetSelector.cpp index ed36ad54..7a4ddc18 100644 --- a/Source/LuckyWorldV2/Private/Gameplay/TargetSelector.cpp +++ b/Source/LuckyWorldV2/Private/Gameplay/TargetSelector.cpp @@ -2,6 +2,8 @@ #include "Gameplay/TargetSelector.h" +#include "Kismet/GameplayStatics.h" +#include "NavigationSystem.h" // Sets default values ATargetSelector::ATargetSelector() @@ -23,5 +25,25 @@ void ATargetSelector::Tick(float DeltaTime) { Super::Tick(DeltaTime); + if (bIsTracing) + { + APlayerController* PlayerController = UGameplayStatics::GetPlayerController(this, 0); + if (PlayerController) + { + FHitResult HitResult; + PlayerController->GetHitResultUnderCursorByChannel(ETraceTypeQuery::TraceTypeQuery1, true, HitResult); + if (HitResult.bBlockingHit) + { + UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent(GetWorld()); + + if (NavSys) + { + FNavLocation NavLocation; + NavSys->ProjectPointToNavigation(HitResult.Location, NavLocation); + SetActorLocation(NavLocation); + } + } + } + } }