Rigid Body components:
Adding a rigid body attribute to an object and setting some parameters can simulate the physical effect of the world:
Add:
Is to select an object, select physical in component, select the Rigidbody
In this case, the object added with the rigid body attribute can fall by gravity.
Specific settings are set in the monitor:
You can set the constant force to apply to an object:
Add the following components:
You can also use a script to configure the settings:
The force of the rigid body is usually set in the fixedupdate () function, as a fixed-time refresh content:
C # The script is as follows:
1 void FixedUpdate()2 {3 rigidbody.AddForce(0.0F,10.0F,0.0F);4 }
Specific settings can be found in Rigidbody documents.
Rigid Body collision and message transmission:
When creating a built-in object, it will automatically set a collision, such as a grid collision tool for a plane object and a spherical collision tool, these things will make some responses when a collision occurs after adding physical properties.
Message transmission in rigid body collision:
In the oncollisionenter function, you can set the logic after the collision.
Example: C #
void OnCollisionEnter(Collider collsion) { print(collsion.gameObject); }
Here, the collison variable is the collision body.
Print the collision object type,
It indicates that when a collision occurs, the function receives the message and responds accordingly;
Trigger collision and message transmission:
Each collision server has a trigger or not option. This option is set to play the scene again without collision effect, however, the collision message is captured and sent to a function named ontriggerenter for execution.
Like this:
void OnTriggerEnter(Collider other) { print(other.gameObject); }
Figure:
The lower left corner shows all collision objects. The main advantage is that collision detection can be performed without affecting the motion of objects;
Above.
Unity physical engine-rigid body collision