Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon

Animation and Unity3D Physics

Save for later
  • 5 min read
  • 27 Oct 2014

article-image

In this article, written by K. Aava Rani, author of the book, Learning Unity Physics, you will learn to use Physics in animation creation. We will see that there are several animations that can be easily handled by Unity3D's Physics. During development, you will come to know that working with animations and Physics is easy in Unity3D. You will find the combination of Physics and animation very interesting.

We are going to cover the following topics:

  • Interpolate and Extrapolate
  • Cloth component and its uses in animation

(For more resources related to this topic, see here.)

Developing simple and complex animations

As mentioned earlier, you will learn how to handle and create simple and complex animations using Physics, for example, creating a rope animation and hanging ball. Let's start with the Physics properties of a Rigidbody component, which help in syncing animation.

Interpolate and Extrapolate

Unity3D offers a way that its Rigidbody component can help in the syncing of animation. Using the interpolation and extrapolation properties, we sync animations.

Interpolation is not only for animation, it works also with Rigidbody.

Let's see in detail how interpolation and extrapolation work:

Create a new scene and save it.

Create a Cube game object and apply Rigidbody on it.

Look at the Inspector panel shown in the following screenshot. On clicking Interpolate, a drop-down list that contains three options will appear, which are None, Interpolate, and Extrapolate. By selecting any one of them, we can apply the feature.

animation-and-unity3d-physics-img-0

In interpolation, the position of an object is calculated by the current update time, moving it backwards one Physics update delta time.

Delta time or delta timing is a concept used among programmers in relation to frame rate and time. For more details, check out http://docs.unity3d.com/ScriptReference/Time-deltaTime.html.

If you look closely, you will observe that there are at least two Physics updates, which are as follows:

  • Ahead of the chosen time
  • Behind the chosen time

Unity interpolates between these two updates to get a position for the update position. So, we can say that the interpolation is actually lagging behind one Physics update.

The second option is Extrapolate, which is to use for extrapolation. In this case, Unity predicts the future position for the object. Although, this does not show any lag, but incorrect prediction sometime causes a visual jitter.

One more important component that is widely used to animate cloth is the Cloth component. Here, you will learn about its properties and how to use it.

Unlock access to the largest independent learning library in Tech for FREE!
Get unlimited access to 7500+ expert-authored eBooks and video courses covering every tech area you can think of.
Renews at €18.99/month. Cancel anytime

The Cloth component

To make animation easy, Unity provides an interactive component called Cloth. In the GameObject menu, you can directly create the Cloth game object. Have a look at the following screenshot:

animation-and-unity3d-physics-img-1

Unity also provides Cloth components in its Physics sections. To apply this, let's look at an example:

Create a new scene and save it.

Create a Plane game object. (We can also create a Cloth game object.)

Navigate to Component | Physics and choose InteractiveCloth.

As shown in the following screenshot, you will see the following properties in the Inspector panel:

animation-and-unity3d-physics-img-2

Let's have a look at the properties one by one. Blending Stiffness and Stretching Stiffness define the blending and stretching stiffness of the Cloth while Damping defines the damp motion of the Cloth. Using the Thickness property, we decide thickness of the Cloth, which ranges from 0.001 to 10,000. If we enable the Use Gravity property, it will affect the Cloth simulation. Similarly, if we enable Self Collision, it allows the Cloth to collide with itself. For a constant or random acceleration, we apply the External Acceleration and Random Acceleration properties, respectively. World Velocity Scale decides movement of the character in the world, which will affect the Cloth vertices. The higher the value, more movement of the character will affect. World Acceleration works similarly. The Interactive Cloth component depends on the Cloth Renderer components. Lots of Cloth components in a game reduces the performance of game. To simulate clothing in characters, we use the Skinned Cloth component.

Important points while using the Cloth component

The following are the important points to remember while using the Cloth component:

  • Cloth simulation will not generate tangents. So, if you are using a tangent dependent shader, the lighting will look wrong for a Cloth component that has been moved from its initial position.
  • We cannot directly change the transform of moving Cloth game object. This is not supported.
  • Disabling the Cloth before changing the transform is supported.
  • The SkinnedCloth component works together with SkinnedMeshRenderer to simulate clothing on a character. As shown in the following screenshot, we can apply Skinned Cloth:

animation-and-unity3d-physics-img-3

As you can see in the following screenshot, there are different properties that we can use to get the desired effect:

animation-and-unity3d-physics-img-4

We can disable or enable the Skinned Cloth component at any time to turn it on or off.

Summary

In this article, you learned about how interpolation and extrapolation work. We also learned about Cloth component and its uses in animation with an example.

Resources for Article:


Further resources on this subject: