10#include "Components/SkeletalMeshComponent.h"
11#include "Components/StaticMeshComponent.h"
12#include "Camera/CameraComponent.h"
13#include "Field/FieldSystemNodes.h"
14#include "Algo/Reverse.h"
17#include "DrawDebugHelpers.h"
22 PrimaryActorTick.bCanEverTick =
true;
23 InteractableName = NSLOCTEXT(
"Agrarsense",
"DroneInteractableName",
"Drone");
32 mesh = Cast<USkeletalMeshComponent>(GetComponentByClass(USkeletalMeshComponent::StaticClass()));
33 desiredPositionMesh = Cast<UStaticMeshComponent>(GetComponentByClass(UStaticMeshComponent::StaticClass()));
40 Super::EndPlay(EndPlayReason);
45 Super::Tick(DeltaTime);
65 FVector currentlocation =
mesh->GetRelativeTransform().GetLocation();
75 UE_LOG(LogTemp, Warning, TEXT(
"Desired location mesh not found"));
80 if (FVector2f::Distance(FVector2f(waypoint.X, waypoint.Y), FVector2f(currentlocation.X, currentlocation.Y)) < 1000)
142 return FVector(0, 0, 0);
153 for (
const FTransform& point : Points)
167 FRotator rotation = FRotator(
168 FMath::Clamp(rotator.Pitch, -2, 2),
169 FMath::Clamp(rotator.Yaw, -2, 2),
170 FMath::Clamp(rotator.Roll, -2, 2));
172 FRotator currentRotation = target->GetRelativeRotation();
174 FRotator rotationDifference = currentRotation - rotator;
176 if (FMath::Abs(rotator.Pitch) > 0 && FMath::Abs(currentRotation.Pitch) < FMath::Abs(rotationDifference.Pitch))
178 target->AddRelativeRotation(FRotator(rotation.Pitch, 0, 0),
false,
nullptr, ETeleportType::TeleportPhysics);
180 if (FMath::Abs(rotator.Yaw) > 0 && FMath::Abs(currentRotation.Yaw) < FMath::Abs(rotationDifference.Yaw))
182 target->AddRelativeRotation(FRotator(0, rotation.Yaw, 0),
false,
nullptr, ETeleportType::TeleportPhysics);
184 if (FMath::Abs(rotator.Roll) > 0 && FMath::Abs(currentRotation.Roll) < FMath::Abs(rotationDifference.Roll))
186 target->AddRelativeRotation(FRotator(0, 0, rotation.Roll),
false,
nullptr, ETeleportType::TeleportPhysics);
189 if (rotator.Pitch == 0 || rotator.Yaw == 0 || rotator.Roll == 0)
191 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);
197 TArray<FTransform> generatedRoamingPoints;
198 generatedRoamingPoints.Reserve(roamingPoints);
200 FVector currentPosition = this->GetTransform().GetLocation();
202 FVector min = currentPosition - FVector(radius / 2, radius / 2, 0);
203 FVector max = currentPosition + FVector(radius / 2, radius / 2, 0);
205 for (int32 i = 0; i < roamingPoints; i++)
207 FTransform randomPoint;
208 randomPoint.SetLocation(FVector(FMath::RandRange(min.X, max.X), FMath::RandRange(min.Y, max.Y), 5000));
210 generatedRoamingPoints.Add(randomPoint);
212 UE_LOG(LogTemp, Warning, TEXT(
"Waypoint %i: (%s)"), i, *randomPoint.GetLocation().ToString());
216 return generatedRoamingPoints;
TArray< FVector > WayPoints
void AssignRoamingPoints(const TArray< FTransform > Points)
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
USkeletalMeshComponent * mesh
void FlySetFlightpath()
Called in tick function for drone roaming through points.
TArray< FTransform > GenerateRoamingPoints(float radius, int32 roamingPoints)
Generates a roadming points array for the drone in radius.
virtual void Tick(float DeltaTime) override
bool IsVehicleInGarage() const
EDroneEndAction DroneEndAction
TArray< FTransform > Points