Unity3d Collision detection and the use of trigger trigger and precautions

Source: Internet
Author: User
first, a new cube, which itself has its own Collider collider, as shown in Figure


To use trigger to detect object entry, you need to tick the IS trigger option
Collision detection trigger trigger is different from the collision detector collision, which can be unaffected by physical effects, some can penetrate the area of the collision detection, you can use the trigger for collision detection
Common methods are as follows:
When Ontriggerenter enters
When Ontriggerexit left
Ontriggerstay in time

The same as the collision detector collision also has 3 methods:
Oncollisionenter
Oncollisionexit
Oncollisionstay

Here we need to add an end line to the runway mechanism, so use a penetrating collision detection trigger trigger

The code is as follows:

1
2
3
4
5
void Ontriggerenter (Collider Collider)
{
Print (collider. Gameobject. Name + ":" + time. Time);

}

Ontriggerenter the parameter passed in must be collider, so the object that can trigger the function must have a collider build. Here we're using the character controller character controllers with Collider build
The role name and system time are printed whenever a character hits a line


Next we use the collision detector collision to perform a collision detection.
First, cancel the is on the object being hit.

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.