7#include "Engine/GameViewportClient.h"
8#include "Engine/OverlapResult.h"
9#include "Engine/EngineTypes.h"
10#include "Engine/Engine.h"
11#include "Engine/World.h"
14#include "DrawDebugHelpers.h"
19 bool ActorPositionWasChanged =
false;
23 return ActorPositionWasChanged;
26 UWorld* World = Actor->GetWorld();
30 const FVector ActorLocation = Actor->GetActorLocation();
31 const FVector StartLocation = ActorLocation + FVector(0.0f, 0.0f, StartZOffset);
32 const FVector EndLocation = ActorLocation - FVector(0.0f, 0.0f, EndZOffset);
34 FCollisionQueryParams QueryParams;
35 QueryParams.AddIgnoredActor(Actor);
36 bool Hits = World->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_WorldStatic, QueryParams);
41 Actor->TeleportTo(HitResult.ImpactPoint, Actor->GetActorRotation());
42 ActorPositionWasChanged =
true;
46 return ActorPositionWasChanged;
60 const FVector CurrentActorLocation = Actor->GetActorLocation();
61 const FVector EndActorLocation = CurrentActorLocation + FVector(0.0f, 0.0f, AboveOffset);
62 Actor->TeleportTo(EndActorLocation, Actor->GetActorRotation());
75 UWorld* World = Actor->GetWorld();
79 FTransform
Transform = Actor->GetActorTransform();
80 FVector ActorLocation =
Transform.GetLocation();
81 FVector ActorScale =
Transform.GetScale3D();
84 FVector MeshExtent = Mesh->GetBounds().BoxExtent;
85 FVector TopExtent = FVector(MeshExtent.X, MeshExtent.Y, MeshExtent.Z * TopPercentage);
87 FVector StartLocation = ActorLocation + FVector(0.0f, 0.0f, MeshExtent.Z);
88 FVector EndLocation = ActorLocation + FVector(0.0f, 0.0f, MeshExtent.Z * TopPercentage);
91 FCollisionQueryParams QueryParams;
92 QueryParams.AddIgnoredActor(Actor);
95 return World->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, CollisionChannel, QueryParams);
106 UE_LOG(LogTemp, Warning, TEXT(
"UPhysicsUtilities.cpp: StaticMesh is null!"));
111 if (!GEngine || !GEngine->GameViewport)
116 TArray<FOverlapResult> OverlapResults;
118 UWorld* World = GEngine->GameViewport->GetWorld();
121 FVector Location =
Transform.GetLocation();
122 FQuat Rotation =
Transform.GetRotation();
124 FBox ActorBounds = StaticMesh->GetBoundingBox().TransformBy(FTransform(Rotation, Location, Scale));
126 World->OverlapMultiByObjectType(
130 FCollisionObjectQueryParams(ECC_WorldStatic),
131 FCollisionShape::MakeBox(ActorBounds.GetSize() * 0.5f)
135 return OverlapResults.Num() > 0;
140 return FindOverlappingActorsOfClass<AActor>(ActorTransform, Radius, DebugVisualizeRadius);
146 TArray<T*> OverlappingActors;
148 if (!GEngine || !GEngine->GameViewport)
150 return OverlappingActors;
153 UWorld* World = GEngine->GameViewport->GetWorld();
157 TArray<FOverlapResult> OverlapResults;
158 FCollisionQueryParams Params;
159 Params.AddIgnoredActor(
nullptr);
160 Params.bTraceComplex =
false;
161 Params.bReturnPhysicalMaterial =
false;
163 FCollisionObjectQueryParams ObjectQueryParams;
164 ObjectQueryParams.AddObjectTypesToQuery(ECC_WorldStatic);
166 bool bOverlap = World->OverlapMultiByObjectType(
168 ActorTransform.GetLocation(),
169 ActorTransform.GetRotation(),
171 FCollisionShape::MakeSphere(Radius),
177 for (
const FOverlapResult& OverlapResult : OverlapResults)
179 T* OverlappingActor = Cast<T>(OverlapResult.GetActor());
180 if (OverlappingActor)
182 OverlappingActors.Add(OverlappingActor);
189 if (DebugVisualizeRadius)
191 DrawDebugSphere(World, ActorTransform.GetLocation(), Radius, 12, FColor::Green,
false, 2.0f, 0, 1.0f);
195 return OverlappingActors;
static bool SnapActorAboveGround(AActor *Actor, float AboveOffset=50.0f)
static bool HasOverlappingActors(const UStaticMesh *StaticMesh, const FTransform &Transform)
static bool DoesTopPercentageMeshOverlap(AActor *Actor, const UStaticMesh *Mesh, float TopPercentage, ECollisionChannel CollisionChannel)
static TArray< T * > FindOverlappingActorsOfClass(const FTransform &ActorTransform, float Radius, bool DebugVisualizeRadius=false)
static TArray< AActor * > FindOverlappingActorsInSphere(const FTransform &ActorTransform, float Radius, bool DebugVisualizeRadius=false)
static bool SnapActorToGround(AActor *Actor, float StartZOffset=600.0f, float EndZOffset=600.0f)