Squash & Stretch Kit – Manual

This is the manual for Squash & Stretch Kit.

How It Works

Traditionally, animators use the squash & stretch technique to enhance the sense of motion. Objects are squashed when experiencing sudden impacts, and are stretched when moving at high speed.

The SquashAndStretch component that comes with Squash & Stretch Kit is the core part of the package. Simply add it to a game object and you’re good to go (although a once-per-project setup described below might be needed). The component scales the object based on velocity and sudden impacts. It also works with Unity’s built in physics (objects with Rigidbody or Rigidbody2D components)!

The direction of squash & stretch is parallel to the object’s direction of motion (the effect axis). When squashed or stretched, not only is the object’s scale parallel to the effect axis changed, the scale perpendicular to the effect axis is also adjusted accordingly in order to preserve volume. So an object becomes fatter when squashed and thinner when stretched.

Once-Per-Project Setup

The logic of the SquashAndStretch component contains two parts, one that happens before all the changes to the game object’s position (pre-position update), and one that happens after (post-position update). The post-position update is already taken good care of in LateUpdate(). The pre-position update is done in Update() that, if not taken care of, could potentially run after other script’s Update() that modifies the game object’s position. This would break the squash & stretch effect.

Unfortunately, until Unity lets us define script execution order at run-time (it used to be possible), the only way to make sure the pre-position update happens before the game object’s position is modified, is through changing the script execution order in the project settings. Here’s how:

  1. In Unity, go to Edit > Project Settings > Script Execution Order.
  2. The Script Execution Order option is now visible in the Inspector window. Add the SquashAndStretch component by pressing the plus (+) button.
  3. The SquashAndStretch component now shows up in the script execution order list.
  4. Move the SquashAndStretch to the top of the list, or at least above any other scripts that can change the game object’s position.

Done! We don’t know if Unity will ever allow us to define script execution order at run-time again. But if that happens, we will be sure to update the SquashAndStretch component so that you don’t have to go through this setup any more.

Note that if a game object is part of Unity’s physics simulation (having a Rigidbody or Rigidbody2D component), the pre-position update happens at FixedUpdate() and does not need this setup, since FixedUpdate() is tied to physics and runs before all calls to Update().

It is also important that you adhere to Unity’s guideline for updating object transforms. All scripts that update an object’s transform should go into Update(). It’s good practice anyway, since people writing their own LateUpdate() would expect all modifications to object transforms to have been done at this point.

Component Parameters

Once a SquashAndStretch component has been added, you can see a list of its parameters in the Inspector menu. This section explains what they mean.

You can also mouse-over a parameter to see a tooltip.

Mode

There are three different modes that you can pick from to best suit your needs.

  • Immediate – Object and squash & stretch effect immediately reflect transform position. Good for objects with mostly smooth position updates while immediate position reflection is desired, such as physically simulated objects.
  • Spring – Object springs behind transform position. Good for when objects stretching past original frontal boundary is undesired. Rate at which spring effect wears off is governed by spring half life.
  • Smooth Immediate – Object position works like immediate mode, squash & stretch effect works like spring mode, and squash & stretch direction is smoothed.Good for objects with potentially jittery movement that could result in visually popping artifacts in immediate mode.

Squash

If squash is enabled, the max squash scale defines the maximum scale in the direction perpendicular to the effect axis. Actual max squash scale is this value or maximum stretch scale reached before squash, whichever is lower. Rate at which squash effect wears off is governed by spring half life.

Stretch

If stretch is enabled, the max stretch scale defines the maximum scale in the direction parallel to the effect axis. Actual stretch scale applied depends on min/max speed thresholds (see below).

Spring Half Life

Anything using the underlying numeric spring simulator depends on this value. Spring half life is the duration (in seconds) over which the spring effect is reduced to 50%. Multiplying the half life by 10 gives roughly the time for spring effect to reduce to 0.1% (1/1024 to be exact). If you’re ever lost, 0.015 is a good value to start tweaking and experimenting from.
Half-life parameterization eliminates the need to guestimate spring constants. Who knows what a spring constant of 1.37 look like anyway!

Min/Max Speed Thresholds

An object begins to stretch as it goes faster than the min speed threshold. The stretch amount is capped at max stretch scale when the object travels at or faster than the max speed threshold.