Unity Tip: Rigidbody Interpolation

Unity LogoWhile working on my Intergalactic Sheep Pong tutorial, I noticed some choppiness when the game was running in Firefox. The graphics would hang and then suddenly unfreeze, revealing objects in new, sometimes drastically different positions.

This was especially befuddling because in the Unity3D editor, I was getting framerates upwards of 1000fps. And in other browsers (such as Safari) the graphics were smooth.

The solution turned out to be simple: I enabled interpolation for the rocket and the sheep rigidbodies. Viola! The jittery behavior disappeared.

Interpolation involves smoothing the motion of objects. In Unity3D, interpolation is used to hide the fact that physics and graphics run at different rates. In some cases, this graphics/physics difference may be so small it’s unnoticeable. But in others, the differences can be so dramatic that the gameplay is hampered. If you’re seeing jerky, choppy behavior in an otherwise well-performing game, you might want to give interpolation a try.

You can read more about rigidbody interpolation here.

EDIT: Since I wrote this post, I’ve learned a bit more about framerate issues.

  1. The frames-per-second (FPS) shown in the Unity Editor stats window is not the actual framerate. It only reflects the time required to draw the graphics. Use this script to see the actual framerate.
  2. If you have fast-moving objects, you might want to use Time.smoothDeltaTime instead of Time.deltaTime.
  3. A couple other parameters that can be used to control choppiness are targetFrameRate and “Sync to VBL”.

One thought on “Unity Tip: Rigidbody Interpolation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s