Unity3d understanding of Rigid bodies (Rigidbody) and Collider (Collider) and triggers (is Trigger), Edge learning Edge Update

Source: Internet
Author: User

The official form of the rigid Body (rigidbody) (from Unity3d's official guidebook "unity4.x to Mastery") is explained below:

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 the performance of an object when it is subjected to a force, as can be seen from the parameters of a 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 doing the experiment found a very strange thing, is that 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 a 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.

Four, A (collision body, close Istrigger), B (collision body and rigid body, open istrigger), no triggering event.

V, A (collision body, open Istrigger), B (collision body and rigid body, close istrigger), 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, for special monitoring of the collision, when the protagonist into the area, the Ontriggerenter event to open the door beforehand.

As shown in figure:




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.