https://api.unrealengine.com/CHN/Engine/Physics/Tracing/index.html
这里使用 World->LineTraceSingleByChannel
void FProEditorModule::DrawPoint(FVector point)
{
UWorld* world = GetWorld();
FVector start = point + FVector(0, 0, 1000);
FVector end = start + FVector(0, 0, -2000);
DrawDebugLine(world, start, end, FColor(255, 0, 0), true, 1000000, 0, 12.333);
FVector forward = FVector(0, 0, 1);
FHitResult OutHit;
FCollisionQueryParams TraceParams;
TraceParams.bTraceComplex = true;
if (world->LineTraceSingleByChannel(OutHit, start, end, ECC_WorldStatic, TraceParams))
{
DrawCircle(world, OutHit.ImpactPoint+ FVector(0, 0, 100), FVector(1, 0, 0), FVector(0, 1, 0), FColor::Blue, 50, 20, true, 10000);
}
}
UWorld * FProEditorModule::GetWorld()
{
UWorld* world = NULL;
for (auto& viewPort : GEditor->LevelViewportClients)
{
world = viewPort->GetWorld();
if (NULL != world)
{
break;
}
}
return world;
}
其中 划线部分使用 #include "DrawDebugHelpers.h"
DrawDebugHelpers中有很多绘制的方法,这里只贴一部分
效果图:
最后需要注意的是:使用 FlushPersistentDebugLines(GetWorld());去除Level中的绘制