#include "EdgingBox.h" #include "Components/BoxComponent.h" // Sets default values AEdgingBox::AEdgingBox() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; // Set up the edging box EdgingBox = CreateDefaultSubobject(TEXT("EdgingBox")); } // Called when the game starts or when spawned void AEdgingBox::BeginPlay() { Super::BeginPlay(); } // Called every frame void AEdgingBox::Tick(float DeltaTime) { Super::Tick(DeltaTime); } void AEdgingBox::MoveTowardsTargetLocation() { // Update target location by actor from target locations by index TargetLocation = TargetLocations[LocationIndex]->GetActorLocation(); // If target location is null if (TargetLocation == FVector::ZeroVector) { UE_LOG(LogTemp, Warning, TEXT("Target Location is null")); return; } // Print string of target location for debugging FString TargetLocationString = TargetLocation.ToString(); UE_LOG(LogTemp, Warning, TEXT("Target Location: %s"), *TargetLocationString) FVector NewLocation = FMath::VInterpTo(TargetActor->GetActorLocation(), TargetLocation, GetWorld()->GetDeltaSeconds(), AttackSpeed); if (NewLocation == FVector::ZeroVector) { UE_LOG(LogTemp, Warning, TEXT("New Location is null")); return; } TargetActor->SetActorLocation(NewLocation); } void AEdgingBox::MoveBackToStartLocation() { // Move to start location by index StartLocation = StartLocations[LocationIndex]->GetActorLocation(); FVector NewLocation = FMath::VInterpTo(TargetActor->GetActorLocation(), StartLocation, GetWorld()->GetDeltaSeconds(), RetractSpeed); TargetActor->SetActorLocation(NewLocation); } void AEdgingBox::IncreaseLocationIndex() { LocationIndex++; } void AEdgingBox::Attack() { // Set current location to start location TargetActor->SetActorLocation(StartLocation); MoveTowardsTargetLocation(); // Delay code here FTimerHandle TimerHandle; GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, &AEdgingBox::MoveBackToStartLocation, AttackActiveTime, false); }