UE4检测网格多个碰撞点

4
我需要找到所有的撞击点(顶点),因为在OnHit中结构体中只有一个撞击点(Impact point)和一个红色调试球。有没有办法做到这一点?(例如,在Unity中,碰撞结构体具有这些点的数组:collision.contacts
这是两个立方体接触面时的示例,有许多接触点(而不是1个)。

введите сюда описание изображения


1
可能可以用C++来实现。看一下UPrimitiveComponent::UpdateOverlapsImplUPrimitiveComponent::ComponentOverlapMulti - Rotem
请注意:有一个“游戏开发”堆栈网站,可以在其中提出UE4问题(https://gamedev.stackexchange.com/)。 - JustLudo
1个回答

2

碰撞会生成重叠事件,因此理论上可以使用OnComponentBeginOverlap并获取SweepResult以获得重叠事件。但是SweepResult不太可靠,因此建议在重叠事件内进行球形扫描

void Pawn::OnComponentBeginOverlap(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, 
int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
 {
     if (OtherActor && (OtherActor != this))
     {
         TArray<FHitResult> Results;
         auto ActorLoc = GetActorLocation();
         auto OtherLoc = OtherComp->GetComponentLocation();
         auto CollisionRadius = FVector::Dist(Start, End) * 1.2f;
 
         // spherical sweep 
         GetWorld()->SweepMultiByObjectType(Results, ActorLoc, OtherLoc,
             FQuat::Identity, 0,
             FCollisionShape::MakeSphere(CollisionRadius),  
             // use custom params to reduce the search space
             FCollisionQueryParams::FCollisionQueryParams(false)
         );
 
         for (auto HitResult : Results)
         {
             if (OtherComp->GetUniqueID() == HitResult.GetComponent()->GetUniqueID()) {

             // insert your code 

                 break;
             }
         }
     }
 }

你可以尝试使用FCollisionQueryParams来加快这个过程,但球形扫描会在几帧碰撞后被绘制,所以也许你可以暂停/停止演员以获得精确的结果。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接