Raycast with Interpolated Rigidbody hit detection (2D)

Hello!

Raycasting a moving Rigidbody that’s interpolated seems to result in inaccurate hit detection. (See below for example)

9784632--1403685--Recording 2024-04-21 at 14.03.48.gif

It may be hard to tell, but you can see that part of the FOV mesh (the brighter bit) is overlapping with the object as it’s moving. Setting the interpolation to none resolves the overlapping issue but then the object is jittery as it’s moving. Extrapalate ends up similar to interpolate, but in the opposite direction or “underlaping”.

Is there a solution to this problem or am I going to have to just pick “the lesser of two evils” whatever that may end up being?

Edit: The Raycasts to build the mesh dynamically happen in LateUpdate

Try tracking the rigidbody’s position and rotation instead of its transform position.

Interpolation does not affect the position/rotation of bodies. It’s a pure Transform/Visual thing used when physics isn’t running in-sync with the frame-rate.

Interpolation updates the Transform to move from the old body pose to the current body pose (historic). Extrapolation updates the Transform to move from the current body pose to a predicted body pose based up on the current velocity (predictive future)

Physics queries don’t care about Transforms of GameObjects, it looks at colliders attached to their bodies.