7#include "Components/StaticMeshComponent.h"
11#include "Field/FieldSystemNodes.h"
13#include <Camera/CameraComponent.h>
17 PrimaryActorTick.bCanEverTick =
true;
18 InteractableName = NSLOCTEXT(
"Agrarsense",
"DroneInteractableName",
"Drone");
27 mesh = Cast<USkeletalMeshComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass()));
28 desiredPositionMesh = Cast<UStaticMeshComponent>(GetComponentByClass(UStaticMeshComponent::StaticClass()));
35 Super::EndPlay(EndPlayReason);
40 Super::Tick(DeltaTime);
58 FVector currentlocation =
mesh->GetRelativeTransform().GetLocation();
68 UE_LOG(LogTemp, Warning, TEXT(
"Desired location mesh not found"));
71 DrawDebugLine(
World, currentlocation, waypoint, FColor::Red,
false, 0.0f, 0.0f, 5.0f);
73 if (FVector2f::Distance(FVector2f(waypoint.X, waypoint.Y), FVector2f(currentlocation.X, currentlocation.Y)) < 1000)
131 return FVector(0, 0, 0);
141 FRotator rotation = FRotator(
142 FMath::Clamp(rotator.Pitch, -2, 2),
143 FMath::Clamp(rotator.Yaw, -2, 2),
144 FMath::Clamp(rotator.Roll, -2, 2));
146 FRotator currentRotation = target->GetRelativeRotation();
148 FRotator rotationDifference = currentRotation - rotator;
150 if (FMath::Abs(rotator.Pitch) > 0 && FMath::Abs(currentRotation.Pitch) < FMath::Abs(rotationDifference.Pitch))
152 target->AddRelativeRotation(FRotator(rotation.Pitch, 0, 0),
false,
nullptr, ETeleportType::TeleportPhysics);
154 if (FMath::Abs(rotator.Yaw) > 0 && FMath::Abs(currentRotation.Yaw) < FMath::Abs(rotationDifference.Yaw))
156 target->AddRelativeRotation(FRotator(0, rotation.Yaw, 0),
false,
nullptr, ETeleportType::TeleportPhysics);
158 if (FMath::Abs(rotator.Roll) > 0 && FMath::Abs(currentRotation.Roll) < FMath::Abs(rotationDifference.Roll))
160 target->AddRelativeRotation(FRotator(0, 0, rotation.Roll),
false,
nullptr, ETeleportType::TeleportPhysics);
164 if (rotator.Pitch == 0 || rotator.Yaw == 0 || rotator.Roll == 0)
166 target->AddRelativeRotation(FRotator(-FMath::Clamp(rotationDifference.Pitch, -2, 2), -FMath::Clamp(rotationDifference.Yaw, -2, 2), -FMath::Clamp(rotationDifference.Roll, -2, 2)),
false,
nullptr, ETeleportType::TeleportPhysics);
172 TArray<FTransform> generatedRoamingPoints;
173 generatedRoamingPoints.Reserve(roamingPoints);
175 FVector currentPosition = this->GetTransform().GetLocation();
177 FVector min = currentPosition - FVector(radius / 2, radius / 2, 0);
178 FVector max = currentPosition + FVector(radius / 2, radius / 2, 0);
180 for (int32 i = 0; i < roamingPoints; i++)
182 FTransform randomPoint;
184 randomPoint.SetLocation(FVector(FMath::RandRange(min.X, max.X), FMath::RandRange(min.Y, max.Y), 5000));
186 generatedRoamingPoints.Add(randomPoint);
188 UE_LOG(LogTemp, Warning, TEXT(
"Waypoint %i: (%s)"), i, *randomPoint.GetLocation().ToString());
192 return generatedRoamingPoints;
void SetDroneRotation(USkeletalMeshComponent *target, FRotator rotator)
FVector GetCurrentWaypointTarget()
void MoveDroneToPosition(const FTransform Transform)
Override all drone roaming points and continue towards this position.
virtual void BeginPlay() override
UStaticMeshComponent * desiredPositionMesh
virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override
void AutoPilot(float DeltaTime)
FDroneParameters DroneParameters
TArray< FTransform > GenerateRoamingPoints(float radius, int roamingPoints)
Generates a roadming points array for the drone in radius.
USkeletalMeshComponent * mesh
void FlySetFlightpath()
Called in tick function for drone roaming through points.
virtual void Tick(float DeltaTime) override
bool IsVehicleInGarage() const
EDroneEndAction DroneEndAction
TArray< FTransform > Points