Hello,
I just need to move the bot to the some place use MoveToLocation.
That’s what I’m doing:
- create BotAiController inherited from AAIController
- in BeginPlay() BotAiController call MoveToLocation()
- create BP from Pawn or Character, assign him BotAiController
- place NavMesh
- place bot on the stage and run
- Must move, but does not move…why?
Equivalent code on bp works.
I have a big old project (4.10) in which much is used MoveTo/MoveToLocation/MoveToActor.
It is important for me to understand why it does not work anymore.
Thanks!
#pragma once
#include "CoreMinimal.h"
#include "AIController.h"
#include "NextAIController.generated.h"
UCLASS()
class TPSPROJECT_API ANextAIController : public AAIController
{
GENERATED_BODY()
virtual void BeginPlay() override;
};
#include "TPSProject.h"
#include "NextAIController.h"
#include "Runtime/Engine/Classes/Kismet/GameplayStatics.h"
#include "Runtime/Engine/Classes/Engine/World.h"
#include "TPSCharacter.h"
void ANextAIController::BeginPlay()
{
GLog->Log("BeginPlay");
UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
ATPSCharacter* player = (ATPSCharacter*)UGameplayStatics::GetPlayerCharacter(GetWorld(), 0);
FVector vec = player->GetActorLocation();
GLog->Log(vec.ToString());
MoveToLocation(vec);
}
Equivalent code on bp:
set up controller: