Chapter 4. Rigidbody Types and Their Properties

In this chapter, we will learn about the types of Rigidbody components and their properties. To detect collision, add gravity, and several other Physics functionalities, a game object must have a Rigidbody component.

In this chapter, we will cover the following topics:

  • Types of Rigidbody components
  • Properties of Rigidbody components
  • Example using Rigidbody components

We can handle a Rigidbody component using a script as well as by manually applying linear and angular velocity.

Note

For accurate Physics calculation, a Rigidbody component requires a collider component.

Types of Rigidbody components

We enable our game objects to act under the control of Physics using Rigidbodies. Here, we will learn how to use and handle a Rigidbody component. A Rigidbody can be handled in two ways:

  • Physics Rigidbody
  • Kinematic Rigidbody

Physics Rigidbody

To influence a game object by gravity or forces, the game object must have a Rigidbody. When a Rigidbody is completely controlled by the engine, it is called a Physics Rigidbody. We can manually apply forces and torque to handle linear and angular velocity of a game object. Manual implementation of forces and torque gives you the freedom to get the desired effect. Let's look at an example of a Rigidbody.

An example of creating a Physics Rigidbody

Use the following steps to apply a Physics Rigidbody:

  1. We will start by creating a new scene and save it as Physics Rigidbody.
  2. Create a Cube game object, as shown in the following screenshot:
    An example of creating a Physics Rigidbody
  3. To enable our game objects to act under the control of Physics, we use Rigidbodies. Add the Rigidbody component to the cube game object, as shown in the following screenshot:
    An example of creating a Physics Rigidbody
  4. In the Inspector panel, make sure that the Is Kinematic property is unchecked. If we enable Is Kinematic, the object can only be manipulated by its Transform property. Generally, we use this for moving platforms or if we want to animate a Rigidbody that has a HingeJoint attached.
    An example of creating a Physics Rigidbody

As shown in the previous steps, we can get the desired effect using the different properties.

Kinematic Rigidbody

When we check the Is Kinematic property of a Rigidbody, it is known as a Kinematic Rigidbody. We cannot apply forces or torque manually to a Kinematic Rigidbody. We can move a Kinematic Rigidbody by changing the values of a GameObject's Transform component. This is useful for moving platforms or animated HingeJoint GameObjects where the engine does not handle the object directly and where we can manipulate its Transform property as per our requirement.

Kinematic Rigidbody

We can use this property by checking it in the Inspector panel, as shown in the previous screenshot. Now, we will learn about the properties of a Rigidbody and their implementation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.65.130