In this lesson, you will learn how to eliminate the visual "stutter" or "jitter" that occurs when your Rigidbody movement doesn't align perfectly with your monitor’s refresh rate.
The Physics-Frame Mismatch
In Unity, physics calculations happen at a fixed interval (defaulting to 0.02 seconds) via FixedUpdate. However, your game’s frame rate (the visual update) often varies depending on your computer's power. Because the physics simulation and the visual rendering are running on two different "clocks," a Rigidbody might move 1.5 units in one physics step, but the frame rate might render it at a position that hasn't quite caught up yet. This causes the object to look like it is vibrating or jittering as it moves.
Solving Jitter with Interpolation
Unity provides a built-in tool to solve this: Interpolation. When you enable interpolation on a Rigidbody, Unity stores the previous frame’s position and the current frame’s position. It then calculates the visual position between those two points based on how much time has passed since the last physics step. Effectively, it "smooths out" the movement so the object looks like it is gliding perfectly, even if the physics simulation is running at a different speed than the frame rate.
How to Apply It
You don’t need complex code to fix this! Simply adjust the settings on your Rigidbody component in the Inspector:
- Select your object with a
Rigidbody. - Locate the Interpolate dropdown menu.
- Change it from "None" to Interpolate.
If you are moving your object via script inside FixedUpdate and notice jittering, this setting is your best friend. While you can technically set this via code as well, it is most common to handle this in the Inspector:
// Example of accessing the interpolation setting via script
void Start() {
Rigidbody rb = GetComponent<Rigidbody>();
rb.interpolation = RigidbodyInterpolation.Interpolate;
}
Key Takeaway: Enable Rigidbody Interpolation to bridge the gap between fixed physics updates and variable frame rates, resulting in buttery-smooth visual motion for your physical objects.