A brief talk on Unity physics engine

Source: Internet
Author: User
Tags float range

Rigid body:

A rigid body is an object that simulates physical effects. Game objects that have a rigid component added are affected by gravity and can be pushed around by the player, or simply add forces to the object to move them around. Typically, the same object is manipulated either by a rigid body or by a transform (transform). However, after adding the rigidbody component and changing the position of the object directly through the transform component, the collision with other objects may be problematic (unless the IS kinematic option is selected and the option is selected, it is not possible to change the motion state of the object by physical simulation). You should avoid using both methods at the same time. The correct method should be to move the rigid body by exerting force or torque.

Property:

Mass quality: The mass of the object (any unit). It is suggested that the mass of an object should not be more than or less than 100 times times that of other units.
Drag Resistance: The air resistance that the object receives when moving. 0 means no, the object immediately stops moving when it is very large.
Angular Drag: Angular resistance when the object is subjected to air resistance when torsion is rotated. 0 means no, the object immediately stops spinning when it is very large.
Whether use Gravity uses gravity
Is Kinematic is kinematics: If activated, the object is no longer driven by the physical engine, but can only be manipulated by transform. Ideal for simulating motion platforms or for simulating rigid bodies connected to hinged joints.
Interpolate interpolation
When you find that the motion of a rigid body shakes, you can try the following options.
None applies interpolation.
Interpolate interpolation is based on the transformation of the previous frame to smooth the transformation of the frame.
Extrapolate extrapolation is based on the predicted transformation of the next frame to smooth the frame transformation.

Collision Detection Collision Detection mode. Used to avoid high-speed objects passing through other objects without triggering a collision.
Discrete discrete

Discrete collision detection. Use the discrete collision detection mode for collision detection with other collider in the scene. This pattern is also applied to other objects and their collision detection. Suitable for normal collisions (this is the default mode).
Continuous continuous
Continuous collision detection. Use discrete collision detection to detect collisions with a dynamic collider (rigid body) and use continuous collision detection to detect collision detection with a static mesh (non-rigid body). The rigid body encountered in the continuous dynamic Collision detection mode will also adopt the continuous collision detection mode. The discrete collision detection mode is used with other rigid bodies. This model is suitable for objects that collide with a dynamic continuous collision pattern. (This has a big impact on physical performance, and if you don't care about collisions with high-speed objects, then let it be the default discrete mode.) )
Continuous dynamic Continuous
Continuous dynamic collision detection. A continuous dynamic collision detection mode is used to detect collisions between objects in continuous mode and continuous dynamic mode. Also suitable for collision detection with static meshes (non-rigid bodies). And the other mode of collision with the object, the use of discrete dynamic collision detection mode. Suitable for high speed objects.
Constraints constraints constrain the movement of rigid bodies. Limits the movement or | and rotation of a rigid body on some dimensions.


Freeze Position freeze position, the rigid body moves in the world along the selected X, Y, Z axis and will not work.
Freeze Rotation freeze rotation, the rigid body rotates in the world along the selected X, Y, Z axis and will not be valid.
Velocity: The velocity vector of a rigid body, it is best not to directly modify it, you can judge the strength of the impact by its size.


Method:
Rigibody.addforce (Vector3), a Vector3 force is added to the center of the object, causing the object to move in the direction of the Vector3, and the motion velocity is the modulus of the vector.
Rigibody.addtorque (Vector3), in the center of the object to add a moment Vector3, the moment can make the object rotation, the rigid body will revolve around the torque axis.
Rigibody.addforceatposition (Vector3,vector3), a force is added to the object at some point, and for the actual effect, the position should be approximately the range of the rigid body surface.
Rigibody.addexplosionforce (float Forcestrength,vector3 postion,float range), add a size of float at a location, The radius is a range of explosive forces (a force applied to objects in various directions within the explosion range) to simulate the explosion effect. The explosive force will decay as the distance to the rigid body is linear.

Tip: The relative mass (Mass) of the two rigid bodies (Rigidbody) determines how they react when colliding with one another.
Making the Mass (Mass) of one rigid body (rigidbody) larger than another (rigidbody) does not cause it to fall faster in freefall. Use Resistance (Drag) for this purpose.
The smaller resistance (Drag) value makes the object look heavier. A higher value makes the object appear lighter. The typical value of resistance (Drag) is between 0.001 (solid metal block) and 10 (feather).
If you are working directly with the object's transform (Transform) component (Component), but you still need physics, attach the rigid body (rigidbody) and set it to Kinematics (kinematic).
If you move a game object (Gameobject) through its transform (Transform) component (Component), but want to receive a collision body (Collider)/trigger (Trigger) message, you must set the rigid body (rigidbody) The object that is attached to the move.
You cannot stop rotation simply by setting its "angular resistance" (Angular Drag) to an Infinity Ambassador object.


Collision body, Trigger
Collision conditions: Two objects must have a collider (Collider), one of the objects must also have a rigidbody rigid body, without the collision of the first experience with each other through. When a collision occurs, when two objects are collider (is trigger not checked) trigger oncollisionxxx, otherwise trigger ontriggerxxx.


Property:
is Trigger if trigger, the Ontriggerxxx method will be triggered when checked, passing through the rigid body
Material material, Back again
Center point for adjusting the position of the collision box
Size of size of the collider on the X, Y, and Z dimensions.
If the convex is active, the mesh collider will collide with other mesh collider. A raised mesh collider is limited to 255 triangular polygons. Mesh collider usually does not collide with each other, but if a mesh collider is marked as raised (convex), it can collide with other mesh collider. A typical solution is to use a basic collider for moving objects and a mesh collider for static environment objects.
Collision Method:
Ontriggerenter (Collider Other) when entering the trigger
Ontriggerexit (Collider Other) when exiting a trigger
Ontriggerstay (Collider Other) when stay trigger
Oncollisionenter (Collision Collisioninfo) when entering the collider
Oncollisionexit (Collision Collisioninfo) when exiting the collider
Oncollisionstay (Collision Collisioninfo) as a stay collider

Static Colliders, a game object that contains a collider but does not contain a rigid body. Instead of moving a static collider one frame at a time, moving the static collider will cause the internal reset of the PhysX engine, which is very resource intensive and can cause a significant decrease in performance.
Layer-based collision detection: Edit->project settings->physics., open the physical reference interface. Select the layer that you want to interact with the other layers in the collision matrix, and check it. (Provided that the layer is set first)

Physical material Physic Material
The physical material is used to adjust the friction and elasticity effects of the colliding object. To create a physical material select Assets->create->physic Material from the menu bar. Then drag the physical material from the project view to a collider on the scene.

Property:
Dynamic friction force friction, the object in the movement of friction, the value range 0~1, the larger the value, the greater the resistance of the object, the faster it stops moving.
Static friction, the object is placed on the surface of the friction force, the value range 0~1, the larger the value, the greater the resistance of the object, the beginning of the movement of the friction, the greater the amount of time, the value of close to 0 can simulate the effect of ice.
Bouncyness elasticity 0 value will not bounce. A 1 value bounce will not have any energy loss.
Friction Combine mode, the friction of two colliding objects is combined.
Average using the average of two frictional forces
Min Use the minimum of two friction values
Max uses the maximum of two friction values
Multiply using two friction products

A brief talk on Unity physics engine

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.