From b381da27444148838c0e0469b7be7ee61cad2b08 Mon Sep 17 00:00:00 2001 From: baz Date: Thu, 8 Feb 2024 23:41:11 +0000 Subject: [PATCH] Create PatrolRoute --- Source/Nakatomi/PatrolRoute.cpp | 34 +++++++++++++++++++++++++++++++++ Source/Nakatomi/PatrolRoute.h | 32 +++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 Source/Nakatomi/PatrolRoute.cpp create mode 100644 Source/Nakatomi/PatrolRoute.h diff --git a/Source/Nakatomi/PatrolRoute.cpp b/Source/Nakatomi/PatrolRoute.cpp new file mode 100644 index 0000000..53761f7 --- /dev/null +++ b/Source/Nakatomi/PatrolRoute.cpp @@ -0,0 +1,34 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "PatrolRoute.h" + +// Sets default values +APatrolRoute::APatrolRoute() +{ + PrimaryActorTick.bCanEverTick = false; + + Spline = CreateDefaultSubobject(TEXT("Spline")); + Spline->SetupAttachment(RootComponent); +} + +void APatrolRoute::IncrementPatrolRoute() +{ + if (PatrolIndex == Spline->GetNumberOfSplinePoints() - 1) + { + Direction = -1; + } + else if (PatrolIndex == 0) + { + Direction = 1; + } + + PatrolIndex += Direction; + + +} + +FVector APatrolRoute::GetSplinePointAtWorld(int pointIndex) +{ + return Spline->GetLocationAtSplinePoint(pointIndex, ESplineCoordinateSpace::World); +} diff --git a/Source/Nakatomi/PatrolRoute.h b/Source/Nakatomi/PatrolRoute.h new file mode 100644 index 0000000..5989f1a --- /dev/null +++ b/Source/Nakatomi/PatrolRoute.h @@ -0,0 +1,32 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Components/SplineComponent.h" +#include "GameFramework/Actor.h" +#include "PatrolRoute.generated.h" + +UCLASS() +class NAKATOMI_API APatrolRoute : public AActor +{ + GENERATED_BODY() + +public: + + UPROPERTY(BlueprintReadWrite) + USplineComponent* Spline; + +private: + int PatrolIndex = 0; + + int Direction; + +public: + // Sets default values for this actor's properties + APatrolRoute(); + + void IncrementPatrolRoute(); + + FVector GetSplinePointAtWorld(int pointIndex); +};