Unity--Collider (collider and Trigger)

Source: Internet
Author: User

(2d and 3d Collider can exist, but cannot collaborate with each other, such as 2d is unable to detect 3d, and vice versa)

In the current situation analysis, the objects involved in the collision in unity are divided into 2 chunks: 1. The object that originated the collision. 2. Receive the colliding object.

1. Launch Collision object: Rigodbody, Charactercontroller.

2. Receive the colliding object by: all collider.

The principle of work is that there must be a "collision" object in the object in which the collision occurs. Otherwise, the collision does not respond.

For example: wall with Boxcollider, so there is no reaction between wall and wall.

For example, a box with a Rigidbody property can fall on the ground with the Meshcollider attribute.

For example: A box with a Rigidbody attribute can be pushed by a person with a Charactercontroller attribute.

That's the reason.

There is a Boolean parameter for the is Trigger on all collider.

This property is checked first when a collision reaction occurs.

When this option is activated, script ontrigger*** is invoked on both sides of the collision, whereas the script does not respond.

When this option is activated, subsequent physical reactions do not occur. Conversely, a subsequent physical reaction occurs.

Summary: Is Trigger is like a physical function switch, whether to "physical function" or "Ontrigger script".

There is a Boolean parameter with the use Gravity on the rigodbody.

Unity physics engine, one of the details of processing:

When a charactercontroller does not occur position changes, a collier occurs after a position change, resulting in a collision. No collision reflection will be invoked.

The physical engine is considered Charactercontroller collision free.

The origin of the collider

1. The system adds a collision component (Collidercomponent) to each object (Gameobject) by default, and some background objects can cancel the component.

2. In Unity3d, there are two ways to detect collisions, one is to use a collider, and the other is to use a trigger. The application of these two methods is very extensive. In order to fully understand both of these approaches, we must understand the following concepts:
(a) Collider is a group of components, it contains a number of types, such as: Box collider,capsule Collider, etc., these collider applications are different, but must be added to Gameobjecet body.
(b) The so-called flip-flop, simply tick the Istrigger attribute selection box in the collider component in the Inspector panel.
(c) In Unity3d, there are mainly the following interface functions to handle these two collision detection:

Trigger Information Detection:
1.monobehaviour.ontriggerenter (Collider Other)/monobehaviour.ontriggerenter2d (collider2d Other) when entering the trigger
2.monobehaviour.ontriggerexit (Collider Other)/monobehaviour.ontriggerexit2d (collider2d Other) when exiting a trigger
3.monobehaviour.ontriggerstay (Collider Other)/monobehaviour.ontriggerstay2d (collider2d Other) when stay trigger

Collision Information Detection:
1.monobehaviour.oncollisionenter (Collision collisioninfo)/monobehaviour.oncollisionenter2d (Collision2D Collisioninfo) when entering the collider
2.monobehaviour.oncollisionexit (Collision collisioninfo)/monobehaviour.oncollisionexit2d (Collision2D Collisioninfo) when exiting the collider
3.monobehaviour.oncollisionstay (Collision collisioninfo)/monobehaviour.oncollisionstay2d (Collision2D Collisioninfo) as a stay collision device

Unity--Collider (collider and 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.