void UCrowdFollowingComponent::FollowPathSegment(float DeltaTime) { if (!bEnableCrowdSimulation) { Super::FollowPathSegment(DeltaTime); return; } if (bUpdateDirectMoveVelocity) { const FVector CurrentTargetPt = DestinationActor.IsValid() ? DestinationActor->GetActorLocation() : GetCurrentTargetLocation(); const FVector AgentLoc = GetCrowdAgentLocation(); const FVector NewDirection = (CurrentTargetPt - AgentLoc).GetSafeNormal(); const bool bDirectionChanged = !NewDirection.Equals(CrowdAgentMoveDirection); if (bDirectionChanged) { CurrentDestination.Set(Path->GetBaseActor(), CurrentTargetPt); CrowdAgentMoveDirection = NewDirection; MoveSegmentDirection = NewDirection; UCrowdManager* Manager = UCrowdManager::GetCurrent(GetWorld()); Manager->SetAgentMoveDirection(this, NewDirection); UE_VLOG(GetOwner(), LogCrowdFollowing, Log, TEXT("Updated direct move direction for crowd agent.")); } } UpdateMoveFocus(); }
void UCrowdFollowingComponent::FollowPathSegment(float DeltaTime) { if (!bEnableCrowdSimulation) { Super::FollowPathSegment(DeltaTime); return; } if (bUpdateDirectMoveVelocity && DestinationActor.IsValid()) { const FVector CurrentTargetPt = DestinationActor->GetActorLocation(); const float DistSq = (CurrentTargetPt - GetCurrentTargetLocation()).SizeSquared(); if (DistSq > FMath::Square(10.0f)) { UCrowdManager* Manager = UCrowdManager::GetCurrent(GetWorld()); const FVector AgentLoc = GetCrowdAgentLocation(); CurrentDestination.Set(Path->GetBaseActor(), CurrentTargetPt); CrowdAgentMoveDirection = (CurrentTargetPt - AgentLoc).GetSafeNormal(); MoveSegmentDirection = CrowdAgentMoveDirection; Manager->SetAgentMoveDirection(this, MoveSegmentDirection); UE_VLOG(GetOwner(), LogCrowdFollowing, Log, TEXT("Updated direct move direction for crowd agent.")); } } UpdateMoveFocus(); }