UE4射线的碰撞与绘制

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 > 0.f) ? LifeTime : LineBatcher->DefaultLifeTime;
        
        LineBatcher->DrawLine(StartPos, EndPos, FLinearColor::Red, 10, 0.f, LineLifeTime);
    }
}

 

posted @ 2017-07-10 14:02  酷熊  阅读(3455)  评论(0编辑  收藏  举报