At first, I used “none” interpolation, until I realized that this wont always position my object 100% accurately.
For instance, I have this character that can jump. When he lands on the ground, his position.y is not always the same. It differs about 0.005f in the y-axis. It’s not much, but it’s not precise, which is pretty important for my game.
Then I tried to set interpolation to extrapolation. Now the y-coordinate is correct after each jump. BUT if I do a jump and fall down to a platform at high speed, the collider will sometimes pass through the platform’s collider for 1frame, and then bring it back up (as far as I understand this extrapolation). Sadly this 1frame of passing collider will cause my character to die.
Is there a way to fix both of these problems, or do I simply have to accept that one of them will occur?
I have also tried Interpolation, but it makes my character very laggy, and uncomfortable to play.
Interpolation interpolates from the old Rigidbody(2D) position to the current Rigidbody(2D) position. It modifies the transform each frame between these positions. In other words, it’s based upon truth but is in the past (it’s interpolating to the current position). This means the Transform changes each frame but the Rigidbody(2D) isn’t changing, it’s at its current position.
Next physics update, the Rigidbody(2D) position is updated and the interpolation starts again from the old to the current position.
Extrapolation works by predicting the future. It interpolates from the current Rigidbody(2D) position to a predicted future position which is calculated by taking the Rigidbody(2D) velocity and integrating it for a single physics tick.
Thus, interpolation is behind the current Rigidbody(2D) position whereas extrapolation is ahead of the current Rigidbody(2D) position.
Box2D uses a tiny gap which it considers a collision. This is to stop continuous overlaps and to provide a buffer region for continuous collision detection. The gap is supposed to be visually insignificant but numerically significant. The gap is ‘0.005f’ which is tiny. It’s 1/200th of a meter (5mm). The scale of your game is too small if 5mm is significant.