Unity learning (four)-physical system

Rigidbody

Rigidbody is the main component of GameObject's physical behavior. Once associated with Rigidbody, the object will be immediately affected by gravity. If one or more Colliders are missing, the GameObject will move due to collision.
Because the Rigidbody component takes over the movement of the GameObject associated with it, you should no longer move the object by changing the Transform property of the script. Therefore, you should use mechanics to drive GameObject and let the physics engine calculate the result. (Learn physics well.)
There are some situations below . You may also need a GameObject with a Rigidbody that will not be controlled by the physics engine. For example, you may need to control your character directly from the script but it can still be detected by triggers (described later). This non-physical movement generated by the script is called kinematic movement. The Rigidbody component has a kinematic attribute, which removes it from the control of the physics engine and moves through the script. It is possible to change the Is Kinematic from the script to allow the physics of opening / closing objects, but there will be some operational overhead (use as little as possible).

Sleep mode

When the Rigidbody moves slower than the predefined minimum line / rotation speed, the physics engine assumes that it has stopped. After doing so, the GameObject will no longer move until it is hit by a collision or force, and enters "sleep" mode. This optimization means that Rigidbody no longer takes the processor's time to update until he is "awakened" again (ie, is in motion again).
In most cases, the Rigidbody component goes to sleep or wakes up obviously. However, if Static Collider (a GameObject without a Rigidbody) modifies the position of the Transform to approach or principle a GameObject, the GameObject may fail to wake up. This may cause the Rigidbody GameObject to hang in the air after the floor is removed from below it. In this case, GameObject uses the WakeUp function to explicitly wake up the GameObject.

Colliders

The Collider component defines the shape of the GameObject for physical collision. Collider is invisible and does not need to be the same shape as the GameObject grid. In gameplay, the approximate grid shape is enough.
The simplest colliders are the initial collider types. In 3D, these categories are Box Collider, Sphere Collider and Capsule Collider. In 2D, you can use Box Collider 2D and Circle Collider 2D.

Compound Colliders

Compound colliders estimate the shape of the GameObject and only consume a small amount of processor overhead. You can also add additional colliders flexibly for child GameObjects. For example, you can rotate the box relative to the coordinate axis of the parent GameObject. When you build such a composite collider, you should only use one Rigidbody component, placed on the source GameObject in the hierarchy.
Initial colliders cannot be used for shear transformation.

Colliders

For some cases, the even number of compound colliders is not accurate enough. In 3D, you can use grid colliders to accurately match the grid shape of GameObject.
This type of colliders consumes more processor resources than the original type and uses as little as possible. Of course, the grid collider will not collide with another grid collider (that is, nothing will happen when they touch). In some cases, you can bypass the feature by marking the grid collider as Convex in the Inspector. This will produce a "convex hull" collider shape. (This shape is very similar to the starting mesh, but there will be no undercut) (?) The advantage of this is that a convex mesh collider can collide with other mesh colliders, so when you have a moving character, You can use this feature.

Static Colliders

You can use static colliders to add colliders to GameObjects without a Rigidbody component to construct floors, walls, and elements that don't need to move in the scene. You cannot reposition static colliders by changing the Transform position, because this will seriously affect the performance of the physics engine. Colliders on GameObjects with Rigidbody are called dynamic colliders. Static colliders can interact with dynamic colliders, but since they do not have a Rigidbody, they cannot move due to collisions.

Physical materials

When colliders interact, their surfaces need to simulate the properties of the materials they represent. For example, a layer of ice is slippery, and a rubber ball will rub and be elastic. Although the shape of colliders does not deform during a collision, their friction and elastic force can be configured by physical materials.

Triggers

When a collision occurs, the script system can detect it and use the OnCollisionEnter function to initiate the action. However, you can also use the physics engine to simply detect that a collider enters other areas when there is no collision. A collider configured as Trigger (using the Is Trigger attribute) is different from solid objects and can simply allow other colliders to pass through. After a collider enters its area, the trigger will call the OnTriggerEnter function in the script of this object.

To be continued....

Guess you like

Origin www.cnblogs.com/qing2019/p/12729518.html