"Swept trace: HitPosition is the surface, EndPosition is the shape centre"
▸ SYMPTOM
A decal or impact effect placed at trace.EndPosition after a .Radius(r) sphere-cast floats a full radius above the surface instead of sitting on it.
▸ CAUSE
For a swept sphere/hull trace, the result carries two positions:
HitPosition— the true surface contact point (result.HitPos)EndPosition— the swept shape's centre at impact (result.EndPos), offset from the surface by the radius
A zero-radius ray trace makes them coincide. But a .Radius(r) sphere-cast puts EndPosition a full radius above the surface. StartPosition is returned when nothing is hit.
▸ FIX
Use HitPosition (and Normal for the surface normal at the contact point) for any surface effect:
var tr = Scene.Trace.Ray(origin, target)
.Radius(16f)
.Run();
if (tr.Hit)
{
// Correct — sits ON the surface
PlaceDecal(tr.HitPosition, tr.Normal);
// Wrong — floats 16 units above the surface
// PlaceDecal(tr.EndPosition, tr.Normal);
}▸ WHY IT WORKS
HitPosition is the actual contact between the swept shape's surface and the world geometry. EndPosition is where the shape's origin (centre) would be if it stopped at that contact — useful for repositioning the swept object, but wrong for surface effects. For a ray (radius 0), the shape's centre IS the surface contact, so they coincide.
- Published