The physics engine is the real physical effect of the game simulation. If two objects collide, the object is free falling, etc. Using Nvidia's PhysX in unity, it renders a realistic picture of the game.
Rigid body
A rigid body is a very well-wanted component.
By default, a newly created object is not physically effective, and a rigid body component can add some common physical properties to an object. For example: quality. Friction. Collisions and so on.
Suppose the object joins a rigid body component. Then it will sense all the physical effects in the physics engine.
Simple to use under
First, wear a game object, and then select the game object you created in the hierarchy view. Then select Component--physics--rigidbody in the Unity navigation menu bar. The following will create 3 cubes. Place it on a volley of ground.
and add a rigid body to one of the cubes. After execution, it was found that the Red Cube sensed physical effects and fell off. While the other two remain in situ.
Properties of a rigid body:
Mass: Quality. The larger the value, the faster the object falls, not more than 10, or it will appear unreal.
Drag: Resistance. The larger the number, the faster the object slows down.
Angular drag: angular resistance. The larger the value, the faster the rotation slows down.
Use Gravity: Whether gravity is used.
Is kinematic: Whether it is affected by physics.
Interpolate: Sets the image difference value.
Collision detection: Collision monitoring.
Constrains: Freezing, stopping the effect of an axial sensing physics engine
Freeze position: Freezes the x-axis. Y-axis, z-axis, direction.
Freeze rotation: Freezes the x-axis. Y-axis. Z axis, rotate.
Physical Manager
In the physical manager, you can set all the physical effects of the entire project. Let's say gravity. Bounce force, speed, etc.
In the menu navigation bar. Select Edit--project setting--physics to open Physics manager.
For example, with:
Gravity: Gravity, by default, the object is under the y-axis downward gravity of 9.8 N, can change the force direction of three axes.
Default material: defaults physical material.
Bounce threshold: Rebound value.
Sleep Velocity: The speed at which it stays in a delicate state when it is slower than the speed of sleep.
Sleep angular velocity: the rate at which the angular velocity is lower than the speed of sleep. does not rotate itself.
Max angular velocity: maximum angular velocity.
Min penetration for penalty: used to minimize penetration after collisions between objects and objects.
Solver Iteration Count: The number of iterations, the default value is 7.
Raycasts hit triggers: Whether or not to start the trigger.
Layer Collision matrix: layers Collision Matrix.
Force
A rigid body component can be subjected to force, such as a force to the x-axis of a rigid body, then the rigid body moves forward along the x-axis. Unity forces in two ways: the normal force, the need to set the direction and size of the force. Target position force. The position of the target point needs to be set, and the object will exert force toward the target position.
Let's take a sample to illustrate. Place a total of two ball objects. After clicking on the normal force, the ball is like a kick.
Click Position Force. The ball will be exerted a force towards the target.
Code:
Using unityengine;using System.collections;public class script_06_02:monobehaviour{//The object that exerts a common force gameobject ADDFRCEOBJ = null;//object Gameobject addposobj = null;//target object Gameobject cubeobj = null;//Use this for initializationvoid Start () { Gets the object that exerts the normal force addfrceobj = Gameobject.find ("Sphere0");//Gets the object that applied the target position force addposobj = Gameobject.find ("Sphere1");// Gets the target object cubeobj= gameobject.find ("Cube"); void Ongui () {if (Guilayout.button ("Normal force?", Guilayout.height (50))) {//apply a force. The direction of the x-axis is 1000,y axis 1000addfrceobj.rigidbody.addforce (1000, 0, 1000);} if (Guilayout.button ("Position Force", guilayout.height (50))) {//Apply a position force. The object will move towards this position. Force mode for the impact.Vector3 force = cubeobj.transform.position-addposobj.transform.position;addposobj.rigidbody.addforceatposition ( Force,addposobj.transform.position,forcemode.impulse);}}}
Perform:
"Unity 3D" Learning note 36: Physics engine--rigid body