http://blog.csdn.net/qq992817263/article/details/51800657
//起点 终点
FHitResult RayGetHitResult(FVector TraceStart, FVector TraceEnd)
{
FCollisionQueryParams TraceParams(FName(TEXT("TraceUsableActor")), true, this);
TraceParams.bTraceAsyncScene = true;
TraceParams.bReturnPhysicalMaterial = false;
TraceParams.bTraceComplex = true; //Hit是用来存储射线的一些数据,如Actor、坐标等等
FHitResult Hit(ForceInit);
if (GetWorld()->LineTraceSingle(Hit, TraceStart, TraceEnd, ECC_Visibility, TraceParams))
{
//绘制射线
DrawRayLine(TraceStart, Hit.Location,0.03f);
}
return Hit;
}
//起点 终点 绘制线的显示的时间
void DrawRayLine(FVector StartPos, FVector EndPos,float fLifeTime)
{
ULineBatchComponent* const LineBatcher = GetWorld()->PersistentLineBatcher;
const float LifeTime = fLifeTime;
if (LineBatcher != NULL)
{
float LineLifeTime = (LifeTime > .f) ? LifeTime : LineBatcher->DefaultLifeTime; LineBatcher->DrawLine(StartPos, EndPos, FLinearColor::Red, , .f, LineLifeTime);
}
}