UE4移动-FHitResult详解
背景
碰撞一般都是通过Trace/Sweep检测, 有了它作为基础, 才能实现移动的具体操作.
Sweep Capsule下的FHitResult
构造测试环境
1 | void ABasePlayerController::TestDoCapsuleTrace(float StartZOffset, float EndZOffset, float InDistance) |
测试结果如图:

FHitResult.Time
\(Time=\frac{FHitResult.Distance}{TraceEnd-TraceStart}\)
1 | /** |
FHitResult.Distance
从trace起始点到碰撞点(还是胶囊体位置)的距离.

1 | /** The distance from the TraceStart to the Location in world space. This value is 0 if there was an initial overlap (trace started inside another colliding object). */ |
FHitResult.Location
当没有bStartPenetrating时为: 碰撞时胶囊体所在位置.
当有bStartPenetrating,
FHitResult.Location和FHitResult.TraceStart相等.

当有bStartPenetrating,
FHitResult.Location和FHitResult.TraceStart相等.


1 | /** |
FHitResult.ImpactPoint
碰撞点位置

1 | /** |
FHitResult.Normal
FHitResult.Normal: 碰撞体(胶囊体)在碰撞点切面的法线.
可以看出, 当胶囊体下半球与物体相撞时候,
FHitResult.Normal过下半球的球心;
当胶囊体中间的圆柱部分与物体相撞时候,
FHitResult.Normal与圆柱的轴线相交.


1 | /** |
FHitResult.ImpactNormal
FHitResult.ImpactNormal: 被碰撞物体在碰撞点切面的法线.
注意当发生Penetrating时,
FHitResult.ImpactNormal等于FHitResult.Normal,
他们都是碰撞体表面法线.

1 | /** |
FHitResult.TraceStart
碰撞检测的起始位置.
1 | /** |
FHitResult.TraceEnd
碰撞检测的结束位置.
1 | /** |
FHitResult.PenetrationDepth
如果碰撞的起始位置在某个物体内部,
则沿着Normal方向移动PenetrationDepth距离,
可以最快脱离碰撞体. 即:
脱离的最短距离为FHitResult.PenetrationDepth.
1 | /** |
FHitResult.bStartPenetrating
是否发生渗透现象, 即碰撞起始点是否在物体内部.
1 | /** |
FHitResult.bBlockingHit
是否发生了Block类型的碰撞, 如果为false则表示发生了Overlap.
1 | /** Indicates if this hit was a result of blocking collision. If false, there was no hit or it was an overlap/touch instead. */ |
FHitResult.PhysMaterial
1 | /** |
FHitResult.Actor
被碰撞物体.
1 | /** Actor hit by the trace. */ |
FHitResult.Component
被碰撞的Component
1 | /** PrimitiveComponent hit by the trace. */ |
FHitResult.BoneName
1 | /** Name of bone we hit (for skeletal meshes). */ |
FHitResult.MyBoneName
1 | /** Name of the _my_ bone which took part in hit event (in case of two skeletal meshes colliding). */ |