Petr003
(Petr003)
1
i want ai to look at me using set focus. but it’s not working. Anyhelp?
#include “Enemy_AIController.h”
#include"Kismet/GameplayStatics.h"
void AEnemy_AIController::BeginPlay()
{
Super::BeginPlay();
APawn*PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(),0);
SetFocus(PlayerPawn);
}
2shk
(Shekhar Tewari)
2
You may try to use the Tick() instead of using the BeginPlay() as then it will be updated every Tick.
Here is the code which worked for me.
void AShooterAIController::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(),0);
if(LineOfSightTo(PlayerPawn))
{
SetFocus(PlayerPawn);
}
else
{
ClearFocus(EAIFocusPriority::Gameplay);
}
}