Oh, I understand now. Yes there is. That is what GetHitResultUnderCursor( ) is doing. The FHitResult passed into GetHitResultUnderCursor( ) will return a Hit.ImpactPoint. ImpactPoint being the world location of where the mouse was clicked.
I used the Third Person Template to mock something up:
[TopDownCharacter.h]
#pragma once
#include "GameFramework/Character.h"
#include "TopDownCharacter.generated.h"
UCLASS(config=Game)
class ATopDownCharacter : public ACharacter
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class USpringArmComponent* CameraBoom;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
class UCameraComponent* FollowCamera;
public:
ATopDownCharacter();
virtual void PossessedBy( AController *In ) override;
virtual void Tick( float DeltaTime ) override;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
float BaseTurnRate;
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category=Camera)
float BaseLookUpRate;
FORCEINLINE class USpringArmComponent* GetCameraBoom() const { return CameraBoom; }
FORCEINLINE class UCameraComponent* GetFollowCamera() const { return FollowCamera; }
protected:
/** User left clicked */
void LeftClick( );
/** Character reached click location */
void ReachedLocation( FVector Reached );
/** Sets a position in world space to move Character to */
void SetNewMoveDestination(const FVector DestLocation);
/** Setup input for user */
virtual void SetupPlayerInputComponent(class UInputComponent* InputComponent) override;
/** Character is moving to Destination (LastWorldMouseLocation) */
bool bTraveling;
/** Last point in world space where user clicked */
FVector LastWorldMouseLocation;
};
[TopDownCharacter.cpp]
#include "TopDown.h"
#include "TopDownCharacter.h"
ATopDownCharacter::ATopDownCharacter()
{
PrimaryActorTick.bCanEverTick = true;
GetCapsuleComponent()->InitCapsuleSize(42.f, 96.0f);
BaseTurnRate = 45.f;
BaseLookUpRate = 45.f;
bUseControllerRotationPitch = false;
bUseControllerRotationYaw = false;
bUseControllerRotationRoll = false;
GetCharacterMovement()->bOrientRotationToMovement = true;
GetCharacterMovement()->RotationRate = FRotator(0.0f, 540.0f, 0.0f);
CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
CameraBoom->SetupAttachment();
FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName);
FollowCamera->bUsePawnControlRotation = false;
}
// When this Character is taken control of by a Controller
void ATopDownCharacter::PossessedBy(AController *In)
{
APlayerController *InController = Cast<APlayerController>( In );
if( InController )
{
InController->bShowMouseCursor = true;
}
Super::PossessedBy( In );
}
// On frame
void ATopDownCharacter::Tick(float DeltaTime)
{
if( (GetActorLocation( ) - LastWorldMouseLocation ).Size( ) < 128.f && bTraveling )
{
ReachedLocation( LastWorldMouseLocation );
bTraveling = false;
}
Super::Tick( DeltaTime );
}
// Reached target location
void ATopDownCharacter::ReachedLocation( FVector Reached )
{
UE_LOG( LogTemp, Warning, TEXT("Reached: %f %f %f"), Reached.X, Reached.Y, Reached.Z );
}
// Setup input (remember to match these Axis and Action in the Input settings)
void ATopDownCharacter::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
check(InputComponent);
InputComponent->BindAction("LeftClick", IE_Pressed, this, &ATopDownCharacter::LeftClick );
}
// Input left click
void ATopDownCharacter::LeftClick()
{
APlayerController *RealController = Cast<APlayerController>(GetController());
if( RealController )
{
FHitResult Hit;
RealController->GetHitResultUnderCursor( ECC_Visibility, false, Hit );
LastWorldMouseLocation = Hit.ImpactPoint;
bTraveling = true;
SetNewMoveDestination( LastWorldMouseLocation );
}
}
// Move to destination, using NavSystem (Level must have a NavMeshBoundsVolume covering walkable space)
void ATopDownCharacter::SetNewMoveDestination(const FVector DestLocation)
{
if( GetController( ) )
{
UNavigationSystem* const NavSys = GetWorld()->GetNavigationSystem();
float const Distance = FVector::Dist(DestLocation, GetActorLocation());
if( NavSys && ( Distance > 120.0f ) )
{
NavSys->SimpleMoveToLocation(GetController( ), DestLocation);
}
}
}