Physics. What is interpolate, extrapolate, discrete, continuous?

I’ve been playing around with physics over the past few days, 2D physics. I understand mostly everything but when it comes to the interpolation and collision modes, I’m confused a bit.

Ill start with interpolate / extrapolate. I understand how each one affects rigidbodies, I turned the fixed timestep up to 0.5 seconds and simply let a body fall. With no interpolation, it was very juttery, with interpolate, it was really smooth as if the fixed timestep was not at 0.5, but slows down as it approaches another collider. Extrapolate also produces juttery results. However when fixed timestep is at the default 0.02 or less, there is no noticeable difference between this modes. But then it’s documented as saying to use interpolate on characters driven by physics to smooth them out. Yet I don’t see this being needed if your fixed timestep is low enough. So am I right in thinking it should be used in games where fixed timestep may be a little higher?

As for collision detection mode, I really really really cannot see any difference at all. I have done a lot of testing to try and see a difference but cannot. People say that discrete collision can cause colliders to pass through each other but I cannot get that to happen at all. No matter how fast I make a rigidbody move into another, it never passes through, ever. Whats the deal here?

Regarding interpolation and extrapolation, you’re right, if the physics frame rate is high then you won’t notice much difference. One time when you will particularly notice a difference is if you arrange for your camera to move at a fixed velocity in Update(), and move a rigidbody at a fixed velocity via the physics. In this scenario, especially with a high render frame rate, you’re likely to see some artefacts which would go away if you enabled interpolation.

My understanding is as follows:

The physics moves in discrete steps, e.g. at t=0.0s, t=0.5s, t=1.0s, t=1.5s. Suppose Unity is rendering a frame at time t=1.2s. It needs to decide what object positions to use.

The first option is to just use the positions calculated for t=1.0s - I believe this is the “None” option. However high the render frame rate is, the object will only visually move when the physics ticks.

The next option is extrapolation. Bear in mind that Unity hasn’t calculated the t=1.5s position yet, because right now t=1.2s. But it can see the object’s state at t=1.0s, including its linear and angular velocities, and extrapolate by assuming the object will continue with those velocities. So the time sinse t=1.0s is 0.2s, and it adds 0.2 times these velocities on to the linear and angular positions, and renders that location.

The last option is interpolation. Instead of guessing where the object might go, instead I believe Unity delays everything by one physics timestep. So at time t=1.0s, it would actually render the objects at their positions from t=0.5s. But it still calculates the physics for t=1.0s, it just doesn’t render those positions yet. Later, at t=1.2s, it can now interpolate 0.2/0.5 of the way between the object positions at t=0.5s and t=1.0s.

Interpolation generally gives the best result, but at the expense of adding latency to the view. Extrapolation kind of works but runs the risk of objects being rendered at odd positions, e.g. penetrating each other, as it can extrapolate through a collision that it hasn’t detected yet.

Again, as you said, it’s often unnecessary to turn on interpolation at all, unless you’ve turned your physics timestep up really high. Generally the things on which you’ll notice problems the most are physics objects which are moving vaguely in sync with non-physics objects that are moved in Update() rather than FixedUpdate(). The most important case is a camera tracking the player character, which is why Unity’s recommendation is to turn interpolation on for the player character, but not for anything else.

I teach Unity certification classes, and I receive a lot of questions about Interpolation and the Collsion Detection properties, so I’ve written articles on them. Interpolation is mainly used to remove jitter in Rigidbody movements, and Collision Detection is used to prevent fast-moving objects from tunnelling through thin objects.

I agree gfoot’s explanation, but i think the point about interpolation is not right. unity doesn’t delay a physics timestep to render, i test interpolation, don’t find delay render, so i think it is just based on previous frames to calculate Velocity and Acceleration. So interpolation is more accurate than extrapolation. Because extrapolation is based on current Velocity, while interpolation is based on current Velocity and Acceleration. In other words, extrapolation is fit for constant Velocity, interpolation is fit for constant Velocity and non-constant Velocity. Certainly, interpolation mode will cost more.