I’m having some odd behavior, and maybe because I’m choosing to use a different Paragon asset for my character, but I’ll see if I can elaborate.
At first, my AI compadres would move towards me but they would float. Their animations wouldn’t play like the Player Controller’s does.
Some Googling led me to this answer:
https://answers.unrealengine.com/questions/821053/how-to-use-paragon-assets-for-ai-character.html
Basic ai characters dont seem to use acceleration for nav movement for … reasons haha no idea why. The paragon assets movements are based on acceleration…
So the fix for that was easy enough. Going into the Character Movement component in our ShooterCharacter BP and toggling on “Use Acceleration for Paths”.
Now the animations play properly when the AI follows me, but now I have another problem.
If I spawn in LOS of the AI, it will follow me and perform all its expected logic I’ve written.
If I don’t spawn in LOS of the AI, when I later move into LOS, it will update the focus because its view will follow me, but it won’t move at all. In fact, in this situation, neither MoveToActor() nor MoveToLocation() will cause the AI to move, but both will update focus successfully.
Is there something else I need to account for in my code when using “Use Acceleration for Paths”?
// --------------------------------------------------------------
void AShooterAIController::BeginPlay()
{
Super::BeginPlay();
// Get reference to player in world.
Player = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
PatrolPosition = K2_GetActorLocation();
MoveToLocation(PatrolPosition);
}
// --------------------------------------------------------------
void AShooterAIController::Tick(float DeltaSeconds)
{
Super::Tick(DeltaSeconds);
bool SeesPlayer = LineOfSightTo(Player, FVector::ZeroVector, true);
if (SeesPlayer) {
SeenPlayer = true;
Elapsed = 0;
// Have this AI focus on the player.
SetFocus(Player);
// Move towards the player.
MoveToActor(Player, FollowDistance);
// Keep this up-to-date so we can move towards this once we lose LOS.
LastKnownPosition = Player->GetActorLocation();
UE_LOG(LogTemp, Warning, TEXT("Moving towards player."));
}
else if (SeenPlayer) {
Elapsed += DeltaSeconds;
// Follow beyond losing LOS so we appear to investigate a bit beyond the last seen corner.
if (Elapsed <= LastKnownPredictionLimit) {
UE_LOG(LogTemp, Warning, TEXT("Moving to last known location."));
LastKnownPosition = Player->GetActorLocation();
}
// Constantly move towards last known position until we lose interest.
MoveToLocation(LastKnownPosition);
if (Elapsed > TimeToLoseInterest) {
UE_LOG(LogTemp, Warning, TEXT("Heading home."));
ClearFocus(EAIFocusPriority::Gameplay);
MoveToLocation(PatrolPosition);
}
}
}
header
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "ShooterAIController.generated.h"
// --------------------------------------------------------------
UCLASS()
class SHOOTER_API AShooterAIController : public AAIController
{
GENERATED_BODY()
public:
virtual void Tick(float DeltaSeconds) override;
protected:
virtual void BeginPlay() override;
private:
UPROPERTY()
APawn* Player;
UPROPERTY(EditAnywhere)
float FollowDistance;
UPROPERTY(EditAnywhere)
float TimeToLoseInterest = 5;
float Elapsed;
float LastKnownPredictionLimit = 1;
bool SeenPlayer = false;
FVector PatrolPosition;
FVector LastKnownPosition;
};
Just to note, this problem does not happen when I toggle “Use Acceleration for Paths” off and use identical logic, just that then the animations won’t play due to the anim graph logic being based on IsAccelerating (which I do like after looking at how it works).