Skip to content

Commit

Permalink
Update US_Minion.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosecchi committed Jun 18, 2023
1 parent bddf8ea commit 619514b
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions Source/UnrealShadows_LOTL/US_Minion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,14 @@ AUS_Minion::AUS_Minion()
void AUS_Minion::BeginPlay()
{
Super::BeginPlay();

SetNextPatrolLocation();
}

void AUS_Minion::SetNextPatrolLocation()
{
if(GetLocalRole() != ROLE_Authority) return;

GetCharacterMovement()->MaxWalkSpeed = PatrolSpeed;

const auto LocationFound = UNavigationSystemV1::K2_GetRandomReachablePointInRadius(
Expand All @@ -71,6 +74,8 @@ void AUS_Minion::SetNextPatrolLocation()

void AUS_Minion::Chase(APawn* Pawn)
{
if(GetLocalRole() != ROLE_Authority) return;

GetCharacterMovement()->MaxWalkSpeed = ChaseSpeed;
// Set the AI character's destination to the player's location
UAIBlueprintHelperLibrary::SimpleMoveToActor(GetController(), Pawn);
Expand Down Expand Up @@ -105,6 +110,8 @@ void AUS_Minion::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

if(GetLocalRole() != ROLE_Authority) return;

if(GetMovementComponent()->GetMaxSpeed() == ChaseSpeed) return;

if((GetActorLocation() - PatrolLocation).Size() < 500.f)
Expand All @@ -117,6 +124,8 @@ void AUS_Minion::PostInitializeComponents()
{
Super::PostInitializeComponents();

if(GetLocalRole() != ROLE_Authority) return;

OnActorBeginOverlap.AddDynamic(this, &AUS_Minion::OnBeginOverlap);
GetPawnSense()->OnSeePawn.AddDynamic(this, &AUS_Minion::OnPawnDetected);
}

0 comments on commit 619514b

Please sign in to comment.