I’m slowly working on a third person action RPG style game and I’ve just started looking at AI.
So far I have an enemy class that inherits from ACharacter and to get things started I wrote a simple function to make the enemy follow the player character (PlayerCharacter below is a pointer to ACharacter*), using the AIController like so;
void AEnemy::MoveToPlayer()
{
if (AIController && PlayerCharacter)
{
FAIMoveRequest MoveRequest;
MoveRequest.SetGoalActor(PlayerCharacter);
MoveRequest.SetAcceptanceRadius(5.0f);
FNavPathSharedPtr NavPath;
AIController->MoveTo(MoveRequest, &NavPath);
}
}
This works great, except when the player character jumps over something. As this is a third person game, I have jumping and if I jump over something that doesn’t have a nav mesh then the enemy character stops moving.
Looking through the docs I found AIController->GetMoveStatus()
which returns EPathFollowingStatus::Idle
once the character has stopped following the player.
I was wondering if there is a way to set up the enemy so it would continue once my player is back on the navmesh, or if not what’s the best way to handle this?
I was thinking of adding a check in tick on the lines of;
if (AIController->GetMoveStatus() == EPathFollowingStatus::Idle) MoveToPlayer();
but that seems like a slow brute force option that might cause problems if there are 10 or more characters all suddenly trying to path to the player at the same time.
Can anyone suggest the best way to keep my enemy’s moving?