Unity3D study notes - physics engine

1. Physics engine

insert image description here

1. Rigidbody

1>Introduction

  • The rigid body can endow the game object with physical characteristics, and the game object receives thrust and torsion under the control of the physical system, so as to realize the physical phenomenon of the real world.

2>Properties

insert image description here
insert image description here

2. Collider

1>Introduction

  • Colliders are a class of physics components that work with rigid bodies to cause collisions
  • Colliders are simple shapes such as cubes, spheres, or capsules that are automatically assigned an appropriate collider whenever a GameObject is created in Unity 3D. A cube will get a Box Collider, a sphere will get a Sphere Collider, a capsule will get a Capsule Collider, etc.

2> classification

  • When the Rigidbody collision component in the game object is added, the corresponding property setting options will be displayed in its property panel, and the resource type of each collision body is slightly different.
    insert image description here

3> Properties

a) Box Collider box collider

  • Box Collider is the most basic collision body, Box Collider is a basic collision body in the shape of a cube
  • General game objects often have Box Collider properties, such as walls, doors, walls, and platforms, etc., and can also be used for the torso of ragdolls or the shells of vehicles such as cars. Of course, they are most suitable for use on boxes or boxes.
    insert image description here
    insert image description here
  • If the Is Trigger option is checked, once the object collides, three collision information will be generated and sent to the script parameters, namely OnTriggerEnter, OnTriggerExit, OnTriggerStay
  • Physics Material defines physical materials, including ice, metal, plastic, wood, etc.

b) Sphere Collider spherical collision body

  • Sphere Collider is a sphere-shaped collider
  • Sphere Collider is a basic sphere-based collision body. The three-dimensional size of Sphere Collider can be adjusted in the same proportion, but the size of a certain axis direction cannot be adjusted separately
  • When the physical shape of the game object is a sphere, use a sphere collision body, such as falling rocks, table tennis and other game objects
    insert image description here
    insert image description here

c) Capsule Collider capsule collision body

  • The Capsule Collider is composed of a cylinder box and two hemispheres. The radius and height of the Capsule Collider can be adjusted independently. It can be used in character controllers or in combination with other irregularly shaped collisions
  • Usually added to the collision attribute of objects such as Character or NPC
    insert image description here
    insert image description here

d) Mesh Collider grid collider

  • Mesh Collider (Mesh Collider) generates a collision body based on the Mesh shape. Compared with Box Collider, Sphere Collider and Capsule Collider, Mesh Collider is more accurate, but it will take up more system resources
  • Specialized for models generated from complex meshes
    insert image description here
    insert image description here

e) Wheel Collider wheel collision body

  • Wheel Collider (wheel collision body) is a special collision body for ground vehicles, with collision detection, tire physics and tire models, specially designed to deal with tires
    insert image description here
    insert image description here

f) Terrain Collider terrain collision body

  • Terrain Collider implements a collision surface with the same shape as the Terrain object it is attached to
    insert image description here
    insert image description here

4>Physical material

  • Used to adjust the friction and bounce effects of colliding objects
    insert image description here
  • Attributes
    insert image description here
    insert image description here

5>Collision conditions

  • To achieve collision detection in unity3D, the following conditions need to be met:
    1. Both objects have a collision component
    2. At least one object has a Rigidbody component
    3. Collider does not check Is Trigger

6>Three stages of collision

  • MonoBehaviour.OnCollisionEnter: Triggered when a collision is entered
  • MonoBehaviour.OnCollisionExit: Triggered when exiting a collision
  • MonoBehaviour.OnCollisionStay: triggered when staying in collision

3. Trigger

1>Introduction

  • In Unity3D, there are two ways to detect collisions:
    1. Using colliders
    2. Using triggers
  • There are triggers in many game engines or tools, which are used to trigger events
  • The difference between a collision body and a trigger is:
    1. The collision body is the carrier of the trigger
    2. The trigger is only an attribute of the collision body
  • If you want to detect physical contact and do not want collision detection to affect the movement of objects, or to detect whether an object passes through a certain area in the control, you can use triggers
  • For example: the collision body is suitable for simulating the effect of the car being knocked into the air, the ball falling on the ground and then rebounding, and the trigger is suitable for simulating the effect of the door automatically opening when the person stands close to the door

2>Trigger conditions

  • To implement trigger detection in unity3D, the following conditions need to be met:
    1. Both objects have a Collider component
    2. At least one object has a Rigidbody component
    3. At least one object’s Collider component has checked Is Trigger
    insert image description here

3> Trigger three stages

  • MonoBehaviour.OnTriggerEnter: fires when a trigger is entered
  • MonoBehaviour.OnTriggerExit: fires when the trigger is exited
  • MonoBehaviour.OnTriggerStay: Triggered when stay in the trigger

4. Constant Force

1> Introduction

  • Constant Force can be used to quickly add a constant force to a rigid body. Constant force is good if you don't want some disposable objects to start with a large velocity but gradually accelerate (like a rocket)
    insert image description here

2> Properties

insert image description here
insert image description here

  • To move the object upwards, add a constant force with a positive Y value to the Force property.
  • To make the object fly forward, add a constant force with a positive Z-value Relative Force property.

5. Character Controller

1>Introduction

  • In Unity 3D, game developers can control the movement of characters through character controllers.
  • Character controllers allow game developers to move subject to collisions without having to deal with rigid bodies
  • The character controller will not be affected by the force. During the game production process, game developers usually add character controller components to the task model to simulate the movement of the model.
    insert image description here

2> Properties

insert image description here
insert image description here

6. Joint

1> Introduction

  • In Unity 3D, the built-in joint component of the physics engine enables the game object to simulate joint motion with joints
  • Joint objects can be added to multiple game objects, and the game objects added with joints will be connected together through joints and have associated physical effects
  • It should be noted that the use of joint components must rely on rigid body components

2> classification

insert image description here

  • Hinge Joint Hinge Joint
    1, Hinge Joint (Hinge Joint) combines two rigid bodies together, and constrains the rigid bodies so that they move as if connected by a hinge.
    2. Hinge joints are great for doors, but can also be used to simulate objects like chains, pendulums, etc.
  • Fixed Joint Fixed Joint
    1, Fixed Joint (Fixed Joint) will limit the movement of the object to depend on another object. This is somewhat similar to parenting, but is achieved through a physics system rather than a Transform hierarchy view.
    2. The best place to use fixed joints is when you want objects to be easily detached from each other, or to connect the movement of two objects without control.
  • Spring Joint Spring Joint
    1, Spring Joint (Spring Joint) connects two rigid bodies together, but allows the distance between the two to change, as if they were connected by a spring
  • Character Joint Character Joint
    1. Character Joint is mainly used for rag doll effect. These joints are extended ball and socket joints that constrain the joint in each axis
  • Configurable Joint Configurable Joint
    1, Configurable Joint (Configurable Joint) contains all the functions of other joint types, and provides more powerful character movement control.
    2. This type of joint is especially useful when you want to customize the movement of the ragdoll and enforce certain poses on the character.
    3. Using configurable joints, you can also modify the joints to highly specialized joints designed by you

3> Properties

a) Hinge Joint hinge joint

insert image description here
insert image description here

b) Fixed Joint fixed joint

insert image description here
insert image description here

c) Spring Joint spring joint

insert image description here
insert image description here

d) Character Joint character joint

insert image description here
insert image description here
insert image description here
insert image description here

  • example
    insert image description here
  • The twist axis (visualized by the orange cones on the gizmo) provides a great deal of control over the upper and lower limits, allowing them to be specified in degrees (the limit angle is measured relative to the start position). A value of –30 in Low Twist Limit > Limit and a value of 60 in High Twist Limit > Limit limits the rotation around the twist axis (orange gizmo) between –30 degrees and 60 degrees.
  • Swing 1 Limit limits the range of rotation of the swing axis (visualized with the green axis on the gizmo). The limiting angles are symmetrical. Therefore, a value of 30 will limit the rotation between –30 and 30.
  • The Swing 2 Limit axis is not shown on the gizmo, but it is perpendicular to the other two axes (the twist axis visualized in orange on the gizmo and the Swing 1 Limit axis visualized in green on the gizmo). The angle is symmetric, so a value of 40 limits rotation around that axis to between –40 and 40 degrees.

e) Configurable Joint configurable joints

insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/Lcl_huolitianji/article/details/121865189