Created
April 20, 2017 18:43
-
-
Save anonymous/047746bba00c331966d06041b86d08c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fill out your copyright notice in the Description page of Project Settings. | |
#include "TD.h" | |
#include "EnemyAI.h" | |
#include "Waypoint.h" | |
#include "EnemyAIController.h" | |
// Sets default values | |
AEnemyAI::AEnemyAI() | |
{ | |
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. | |
PrimaryActorTick.bCanEverTick = true; | |
} | |
// Called when the game starts or when spawned | |
void AEnemyAI::BeginPlay() | |
{ | |
Super::BeginPlay(); | |
AIController = Cast<AEnemyAIController>(GetController()); | |
UGameplayStatics::GetAllActorsOfClass(GetWorld(), AWaypoint::StaticClass(), Waypoints); | |
MoveToWaypoints(); | |
} | |
// Called every frame | |
void AEnemyAI::Tick(float DeltaTime) | |
{ | |
Super::Tick(DeltaTime); | |
CurrentVelocity = GetCharacterMovement()->Velocity; | |
} | |
// Called to bind functionality to input | |
void AEnemyAI::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) | |
{ | |
Super::SetupPlayerInputComponent(PlayerInputComponent); | |
} | |
void AEnemyAI::MoveToWaypoints() | |
{ | |
if (CurrentWaypoint > 1) | |
{ | |
GetCharacterMovement()->Velocity = CurrentVelocity; | |
} | |
if (AIController) | |
{ | |
if (CurrentWaypoint <= Waypoints.Num()) | |
{ | |
for (AActor* Waypoint : Waypoints) | |
{ | |
AWaypoint* WaypointItr = Cast<AWaypoint>(Waypoint); | |
if (Waypoint) | |
{ | |
if (WaypointItr->GetWaypointNumber() == CurrentWaypoint) | |
{ | |
AIController->MoveToActor(Waypoint, 5.f, false); | |
break; | |
} | |
} | |
} | |
} | |
} | |
CurrentWaypoint++; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "TD.h" | |
#include "EnemyAI.h" | |
#include "EnemyAIController.h" | |
void AEnemyAIController::OnMoveCompleted(FAIRequestID RequestID, const FPathFollowingResult& Result) | |
{ | |
AEnemyAI* EnemyAI = Cast<AEnemyAI>(GetControlledPawn()); | |
if (EnemyAI) | |
{ | |
EnemyAI->MoveToWaypoints(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment