Physics simulations

In this section, you will learn what Unity has to offer in terms of a physics engine.

Also known as physics simulations, these engines have been an integral part of 3D and game engines for some time, but rarely are they as easy to get into as with Unity.

A physics engine is a basic physics simulation that allows the developer to add physical properties to GameObjects, such as weight, gravity, bounce, and other factors that allow these GameObjects to act and react in different ways:

  1. Select the Hello object in the Hierarchy panel.
  2. Click on the Add Component button in the TextMesh component in the Inspector panel.
  1. Click on the Physics category:
  1. Then, select Rigidbody:
  1. Now, repeat steps 1, 2 and 3.
  2. Select Box Collider.
  3. Now, the first word is finished; we need to repeat steps 1-6 for the World object.

The Rigidbody is a component that lets Unity apply physics to an object. You can change many of the ways the object reacts to the physical changes.

The Box Collider allows the object it is applied to register collisions with other objects. The object must also have a collider of some sort. There are six types of 3D physics colliders, including sphere, capsule, and mesh for complex objects.

Now, that we have our physics components on our objects, let's set up the scenes gravity. Here, we will lighten the gravity a bit and apply a different amount of drag to each object so that they fall differently. Let's perform the following steps to do this:

  1. Click on the Edit menu option, and select the Project settings near the bottom of the menu:
  1. Click on the Physics option. This will bring up the Physics Manager in the Inspector:

Look at the first field, Gravity Y is our vertical axis. Unity has a constant gravity of -9.81 by default. 0 would be no gravity at all, and a positive number would make objects move upward.

Select the number in the Gravity Y axis and change it from -9.81 to -6.

Now, we will make a couple of changes on a per-object level so that the physics reactions are different:

  1. Select the Hello object in the Hierarchy panel.
  2. Look for the Inspector and scroll down to the Rigidbody component.
  3. Find the Drag heading and change the number to 2.
  4. Change the number in Angular Drag to 1:

Now, we will make a similar change to the World text object:

  1. Select World in the Hierarchy panel.
  2. Again, look for the Inspector and scroll down to the Rigidbody component.
  3. Change the Drag setting to 3.
  4. Change Angular Drag to 2.
  5. Now, let's save our scene by pressing Ctrl + S.
..................Content has been hidden....................

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