Course contentsShow
← Unity Game Development
Lesson 185 of 8283. Physics and InteractionFree lesson

Damping Movement to Eliminate Jitter

Learners will apply linear drag and velocity smoothing techniques to remove erratic vibrations caused by physics engine calculations.

In this lesson, you will learn how to stabilize physics-driven movement by applying linear drag and velocity smoothing to eliminate erratic, high-frequency vibrations known as "jitter."

Understanding Physics Jitter

Jitter often occurs when a physics body experiences conflicting forces—such as constant gravity fighting against a high-speed movement script, or collisions that trigger micro-corrections every frame. When these forces compete, the object may bounce or tremble in place because the physics engine is trying to resolve conflicting states of motion.

Applying Linear Drag

The simplest way to calm an erratic object is through Linear Drag. In the Rigidbody component, the Drag property simulates air resistance. By increasing this value, you force the object to lose velocity over time, which prevents it from "overshooting" its target position and oscillating back and forth.

Think of Drag as a filter that dampens extreme velocity spikes. If your object is shaking while moving, a small amount of Drag (e.g., 1.0 or 2.0) can provide enough friction to settle the motion.

Smoothing with Velocity Clamping

When applying manual movement forces, you can further stabilize the jitter by manually clamping the velocity within your movement script. Instead of allowing forces to accumulate indefinitely, we cap the velocity of the Rigidbody so it stays within a predictable range:

void FixedUpdate() 
{
    // Define a maximum speed to prevent erratic physics spikes
    float maxSpeed = 10f;
    
    // Clamp the velocity to ensure smooth, predictable motion
    rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
}

By using FixedUpdate for these calculations, you ensure that your dampening logic syncs perfectly with the physics engine’s own update loop. This prevents the "tug-of-war" between your movement code and the physics simulator, leading to much cleaner movement.

If you still notice jitter after applying drag and clamping, check your Rigidbody interpolation settings. Setting it to Interpolate will smooth out the visual transition between physics frames, making the movement appear fluid even if the underlying calculations are slightly erratic.

Key Takeaway: Jitter is caused by conflicting physics forces; resolve it by increasing Linear Drag to dampen energy and using velocity clamping to bound maximum motion speed.