// Fill out your copyright notice in the Description page of Project Settings. #include "Gameplay/TargetSelector.h" #include "Kismet/GameplayStatics.h" #include "NavigationSystem.h" // Sets default values ATargetSelector::ATargetSelector() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; } // Called when the game starts or when spawned void ATargetSelector::BeginPlay() { Super::BeginPlay(); } // Called every frame 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); } } } } }