Reprint Unity3d Understanding Rigid Body (rigidbody) and collision Body (Collider) and trigger (is Trigger)

Source: Internet
Author: User

Reconciled articles, some of the original author's conclusions are classic.

the official of the rigid body (rigidbody) (excerpt from Unity3d's official guidebook "unity4.x from Beginner to Mastery") The explanations are as follows:

The Rigidbody (rigid body) component allows the game object to be controlled in the physical system, and the rigid body accepts external forces and torque forces to ensure that the game object moves as it does in the real world. Any game object can be affected by gravity only by adding a rigid body component, and the action that is added by the script for the game object and the interaction between the Nvidia physics engine and other game objects requires the game object to add a rigidbody component.

personal understanding is that a rigid body is used to simulate an object's performance when subjected to a force, This can be seen from the parameters in the rigid body:


It is all about the parameters of how the object is subjected to force, such as mass mass, drag resistance.


The official of the collider (excerpted from Unity3d's official guidebook "unity4.x from Beginner to Mastery") explains the following:

A collision body is a class of physical components that are added to a game object with a rigid body to trigger collisions. If two rigid bodies collide with each other, the physical engine calculates collisions unless two objects have collisions, and in a physical simulation, the first experience without the collider crosses each other.


The individual is so understanding, why to judge the collision is the need to calculate the force, whether it is resistance or power, if the object has a rigid body assembly, then the object will be in force under the action of motion. If the object does not have a rigid body, then the force generated by the collision has no meaning, and the calculation of the collision has no meaning.

So, we can infer that if two colliding bodies have no rigid components, then the two objects will not collide if they collide with each other.


The collision on the official website is as follows (note: It is said to be the official website of the map, I have seen many places on the internet, but I have not found in the official website where ha):


From the above figure we can see that there must be a rigidbody on both sides of the collision, and both sides of the collision have to have colliding body components.


But when we did the experiment, I found a very strange thing . The subject of the collision must be with a rigid body, that is, only the collision body with a rigid body to hit other colliding bodies, the two sides will receive the collision event , the following is my experiment:

One, the control of a (rigid body and collision body) hit a stationary B (only collision body), the two sides can receive a collision event.

Second, control B (only collision body) hit stationary A (rigid body plus collision), the two sides do not receive the collision event.

Third, let a (rigid body and collision body) fall freely, and then control B (only collision body) to hit a, both sides can be affected by the collision event.


The conclusion seems to be that if there is only one rigid body on both sides of the collision, then the rigid body must be in a state of motion before a collision event occurs.


Next is the Istrigger option, which does not trigger the message, and first enumerates the triggering events and collision events, as follows:

Trigger Information detection:
1.monobehaviour.ontriggerenter (Collider Other) when entering the trigger
2.monobehaviour.ontriggerexit (Collider other) when exiting a trigger
3.monobehaviour.ontriggerstay (Collider other) when stay trigger

Collision Information Detection:
1.monobehaviour.oncollisionenter (Collision collisioninfo) when entering the collider
2.monobehaviour.oncollisionexit (Collision collisioninfo) when exiting the collider
3.monobehaviour.oncollisionstay (Collision collisioninfo) as a stay collider

Here is a diagram of the trigger, as follows (note: Also from the internet, I have not yet found on the official website ha)



Here is what I do test, is a object to hit B object.

A, a ( collision body ), B (no collider, no rigid body), no triggering event.

Second, A (collision body), B (collision body), no triggering event.

Two, A (collision body and rigid body, open Istrigger), B (collision body, close Istrigger), both sides can receive the trigger event.

Three, A (collision body and rigid body, close istrigger), B (collision body, open Istrigger), both sides can receive the trigger event.

IV, A ( colliding body, closing istrigger ), B ( Collider and rigid body, open istrigger ), no triggering event.

V, A ( colliding body, opening istrigger ), B ( Collider and rigid body, close istrigger ), there is no triggering event.


Additional experiments:

Six, a ( collision body and rigid body, open Istrigger) Free fall, B (collision body) hit A, both sides can receive trigger events.


According to the above experiment, if you want to receive a trigger event, the following three conditions must be met:

1, must have a collider component (Collider), in fact, the above collision events also need this prerequisite.

2, there must be an object with a rigid body assembly, and in the movement of the body (including the active movement to impact on others and in the course of the movement by others hit).

At least one of the 3, two collider Istrigger is turned on.


In addition, there are two points:

The two objects that generate the triggering event will cross each other, precisely because the object that is opened Istrigger is ignored by the physical engine lock, so two objects can be traversed.

Two, two objects either receive a collision event, or both receive a trigger event, no event is received, and a collision event is received.


Another point of experience is that when you control an object A to hit another object B, do not directly modify the position property of the transform of object A, because you will find that if even the two collisions are still going through, the reason is that we are directly set the coordinates, If object A has a rigid body component, it should use Addforce to add a force to the object, and then let the physics engine move the object so that if a collision occurs, it will not cross.


Well, in the afternoon after a long time, I have been thinking of that istrigger have what use, later on the internet search, said is can do the door automatically open, let me think of the Unity3d 4 of which angrybots example, seemingly when the control protagonist walked to a door, the door will automatically open.

so open the example project, to see, and found that sure enough, the principle is to put a set of istrigger in front of the transparent collision body, used to monitor the collision, when the protagonist into the area, through Ontriggerenter Event The door was opened in advance.



Transferred from: http://blog.csdn.net/monzart7an/article/details/22739421

Reprint Unity3d Understanding Rigid Body (rigidbody) and collision Body (Collider) and trigger (is Trigger)

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.