I have a question about the movement of AI

void AShooterAIController::BeginPlay()
{
    Super::BeginPlay();

    APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);
    
    SetFocus(PlayerPawn);

    
}
void AShooterAIController::Tick(float DeltaSeconds)
{
    Super::Tick(DeltaSeconds);
    APawn* PlayerPawn = UGameplayStatics::GetPlayerPawn(GetWorld(), 0);


    MoveToActor(PlayerPawn, 200);
}

There is something I don’t understand even though I took a lecture haha…

MoveToActor only moved once when I wrote it on BeginPlay and it hasn’t moved since. Why?
And SetFocus requires AI to keep looking at players as they move. But I wonder why they’re calling from BeginPlay, not Tick.

Maybe I’m being too stupid…

The character/movement class has all of that logic, which would be done in tick. All you’re doing is setting what the focus actor/goal for movement is.

I’m sorry, I didn’t quite catch that. Could you please repeat it?

The movement isn’t done by calling those functions. They’re just telling it what it should move to and focus on.

The character movement component and the AI controller class are what’s doing the moving and focusing in their tick.

Movement is focused on movement by calling from Tick.
Are you referring to this?

I’m not sure what you’re trying to say.

To hopefully be clearer; neither SetFocus or MoveToActor focus on the actor or move to the player.
This isn’t how its implemented but to give you an idea

void AAIController::SetFocus(AActor* Focus)
{
    FocusActor = Focus;
}

void AAIController::MoveToActor(AActor* Actor)
{
    TargetActor = Actor;
}

void AAIController::Tick(float DeltaTime)
{
    // ...
    if (TargetActor)
    {
        MoveTo(TargetActor);
    }
    if (FocusActor)
    {
        RotateTo(FocusActor);
    }
}

again; this isn’t exactly how its implemented but its to demonstrate that the functionality of moving and focusing aren’t in the two functions in your OP.

I saw it too late. Thank you.

Privacy & Terms