"SceneTrace sphere sweep EndPosition is the sphere centre, not the feet"
▸ SYMPTOM
You run a sphere-radius sweep to find where a character lands (ground snap, step-down) and use SceneTraceResult.EndPosition as the feet/contact position. Bodies end up floating or sunk by a fixed amount — an origin that sits a full sphere radius above or below the real surface — and the error is consistent, not random.
▸ CAUSE
SceneTraceResult.EndPosition on a sphere sweep is the sphere's centre at the moment of contact, not the point where the sphere touched the geometry. The contact point is one radius further along the sweep direction. Read the centre as "where the feet landed" and every result is off by exactly the sphere radius. Because the offset is constant it reads like a tuning problem rather than a wrong-quantity bug, so it tends to get "fixed" with a magic offset at one call site and then reappear at the next call site that forgot it.
▸ FIX
Derive the actual contact/feet position from the sweep fraction, and do it in one wrapper so the radius offset can't silently creep back in:
Vector3 GetFeetPosition(Vector3 from, Vector3 to, SceneTraceResult r)
=> from + (to - from) * r.Fraction;Call that everywhere instead of re-deriving the position per call site. This single distinction removes a whole class of off-by-a-radius bugs in ground snaps and step-downs.
Related: the tangent-contact StartedSolid trap
If a ground snap lands the sphere exactly tangent to the floor (feet flush with the surface), the next horizontal sweep intermittently reports StartedSolid. A sphere touching a plane at a single point is a degenerate contact: floating-point noise on the following frame can put the lower hemisphere infinitesimally on the wrong side of the surface, which some sweeps read as already embedded.
Fix: snap the body standing one unit proud of the floor rather than exactly flush. That removes the tangent degenerate case entirely, at the cost of one unit of visual float that is imperceptible at character scale.
▸ WHY IT WORKS
Fraction is the scalar position along the swept segment at contact, so from + (to - from) * Fraction is the true point the swept shape reached along its own path — independent of the shape's radius. Standing one unit proud replaces a single-point (measure-zero) contact with a small positive gap, so the next frame's sweep starts unambiguously outside the geometry.
- Published