I have a next problem. In the RTS demo I have send message to character for moving to actor. Character starts moving and irregularly moving.
Character class
UCLASS(BlueprintType)
class AThirdPersonShooterCharacter : public ACharacter
{
GENERATED_UCLASS_BODY()
public:
// ...
UBlackboardComponent* GetBlackboard();
void MoveToLocation(const FVector& Loc);
bool IsMoving() const;
FVector SelectedMovingLocation;
protected:
// ...
UPROPERTY()
AActor* m_MoveTarget;
};
void AThirdPersonShooterCharacter::MoveToLocation(const FVector& Loc)
{
if (m_MoveTarget == nullptr)
{
AActor* A = GetWorld()->SpawnActor(ANavigationTestingActor::StaticClass());
m_MoveTarget = A;
if (m_MoveTarget == nullptr)
return;
auto BB = GetBlackboard();
if (BB == nullptr)
return;
BB->SetValueAsObject(TEXT("MovingTarget"), m_MoveTarget);
}
SelectedMovingLocation = Loc;
if (!IsMoving())
{
m_MoveTarget->SetActorLocation(Loc);
return;
}
auto AIController = Cast<AAIController>(Controller);
if (AIController == nullptr)
return;
m_MoveTarget->SetActorLocation(Loc);
}
bool AThirdPersonShooterCharacter::IsMoving() const
{
auto AIController = Cast<AAIController>(Controller);
if (AIController == nullptr)
return false;
return AIController->GetMoveStatus() == EPathFollowingStatus::Moving;
}
UBlackboardComponent* const AThirdPersonShooterCharacter::GetBlackboard() const
{
if (Controller == nullptr)
return nullptr;
auto AIController = Cast<AAIController>(Controller);
if (AIController == nullptr || AIController->BrainComponent == nullptr)
return nullptr;
return AIController->BrainComponent->GetBlackboardComponent();
}
Place a target for my characters:
FHitResult Hit;
if (!GetHitResultUnderCursor(ECC_WorldStatic, false, Hit))
return;
const auto& Loc = Hit.Location;
for (auto Player : Players)
{
Player->MoveToLocation(Loc);
Player->SetUserInput(true);
}
Behavior tree:
“Before moving” task is simply sets an animation for running.
But my character randomly stops during moving. I was played around with the values of Navigation System agent’s properties but unsuccessfully. My map’s size is 1 square km. Nav agent properties is default.