Files
LuckyWorld/Source/LuckyWorldV2/Private/Gameplay/TargetSelector.cpp

50 lines
1.2 KiB
C++
Raw Normal View History

2025-04-11 12:41:50 +08:00
// Fill out your copyright notice in the Description page of Project Settings.
#include "Gameplay/TargetSelector.h"
2025-04-14 10:45:07 +08:00
#include "Kismet/GameplayStatics.h"
#include "NavigationSystem.h"
2025-04-11 12:41:50 +08:00
// 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);
2025-04-14 10:45:07 +08:00
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<UNavigationSystemV1>(GetWorld());
if (NavSys)
{
FNavLocation NavLocation;
NavSys->ProjectPointToNavigation(HitResult.Location, NavLocation);
SetActorLocation(NavLocation);
}
}
}
}
2025-04-11 12:41:50 +08:00
}