Agrarsense
PhysicsUtilities.h
Go to the documentation of this file.
1// Copyright (c) 2023 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#pragma once
7
8#include "CoreMinimal.h"
9#include "Kismet/BlueprintFunctionLibrary.h"
10#include "CollisionQueryParams.h"
11#include "Engine/StaticMesh.h"
12
13#include "PhysicsUtilities.generated.h"
14
15class AActor;
16
20UCLASS()
21class AGRARSENSE_API UPhysicsUtilities : public UBlueprintFunctionLibrary
22{
23 GENERATED_BODY()
24
25public:
26
34 UFUNCTION(BlueprintCallable, Category = "Physics Utilities")
35 static bool SnapActorToGround(AActor* Actor, float StartZOffset = 600.0f, float EndZOffset = 600.0f);
36
43 UFUNCTION(BlueprintCallable, Category = "Physics Utilities")
44 static bool SnapActorAboveGround(AActor* Actor, float AboveOffset = 50.0f);
45
54 UFUNCTION(BlueprintCallable, Category = "Physics Utilities")
55 static bool DoesTopPercentageMeshOverlap(AActor* Actor, const UStaticMesh* Mesh, float TopPercentage, ECollisionChannel CollisionChannel);
56
63 UFUNCTION(BlueprintCallable, Category = "Physics Utilities")
64 static bool HasOverlappingActors(const UStaticMesh* StaticMesh, const FTransform& Transform);
65
73 UFUNCTION(BlueprintCallable, Category = "Physics Utilities")
74 static TArray<AActor*> FindOverlappingActorsInSphere(const FTransform& ActorTransform, float Radius, bool DebugVisualizeRadius = false);
75
76 /*
77 * Adjusts the transform's Z position so the actor is placed at the specified height above ground.
78 * The incoming Transform.Z is treated as the desired height **in meters** above the terrain.
79 * Performs a downward trace to find the ground and sets Z accordingly.
80 */
81 UFUNCTION(BlueprintCallable, Category = "Physics Utilities")
82 static bool AlignTransformFromGroundInMeters(AActor* Actor, FTransform& InTransform);
83
91 template<typename T>
92 static TArray<T*> FindOverlappingActorsOfClass(const FTransform& ActorTransform, float Radius, bool DebugVisualizeRadius = false);
93
94};