What I’m attempting to do is allow the player to click a character to select it, then click somewhere else to move it to the location clicked. Possession is out of the question because the player needs to maintain control over the player character, which for now I’m just using the default you get when you make a new basic code project. Is there any alternative to possession that allows me to select a pawn, then use something like NavSys->SimpleMoveToLocation without losing control of the player’s character? Here’s my playercontroller cpp:
#include "GridTest.h"
#include "MainPlayerController.h"
#include "AI/Navigation/NavigationSystem.h"
AMainPlayerController::AMainPlayerController(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
bShowMouseCursor = true;
SelectedCharacter = NULL;
}
void AMainPlayerController::SetupInputComponent()
{
Super::SetupInputComponent();
InputComponent->BindAction("SelectOrMove", IE_Pressed, this, &AMainPlayerController::HandleClick);
}
void AMainPlayerController::HandleClick()
{
//Trace to see what is under the mouse cursor
FHitResult Hit;
GetHitResultUnderCursor(ECC_Visibility, false, Hit);
//If hit
if (Hit.bBlockingHit)
{
//Cast pawn to character
ACharacter * const SelectCharacter = Cast<ACharacter>(Hit.GetActor());
//If successful
if (SelectCharacter)
{
//Set the currently selected character
SelectedCharacter = SelectCharacter;
}
else
{
//If a character is selected, move the character
if (SelectedCharacter)
{
//Move character?
}
}
}
}
Any help would be greatly appreciated.