官术网_书友最值得收藏!

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.
主站蜘蛛池模板: 永兴县| 石柱| 沅陵县| 德阳市| 大理市| 盐池县| 合阳县| 十堰市| 三都| 当雄县| 德保县| 绩溪县| 建湖县| 巧家县| 郯城县| 双江| 项城市| 西乌| 邓州市| 徐水县| 新乡县| 桃源县| 晴隆县| 固镇县| 镇巴县| 岳普湖县| 金溪县| 台北市| 奉新县| 凤庆县| 宁晋县| 洱源县| 郯城县| 监利县| 马公市| 馆陶县| 七台河市| 新密市| 江口县| 全州县| 霍邱县|