Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by boddole · Apr 29, 2015 at 07:27 AM · c#collidercollidersontriggerenterbounds

How Does OnTriggerEnter() Work?

Hello everyone, the question I'm asking is probably more involved than the title would make it appear. Specifically, I'm asking how this method (and its related methods) actually go about figuring out if an object has entered / remains inside / has exited a collider.

For example, I could use collider.bounds.Contains() to check if a point is inside a sphere/capsule/mesh collider, but since bounds is "just a box" the result may not be accurate at all. Yet, OnTriggerEnter() will give an accurate result. So I'm after what makes that method so accurate over something like bounds.Contains(), or in other words, how to build my own method similar to OnTriggerEnter() / OnTriggerStay().

In my specific case, I'm trying to check if "objects of interest" are within some of my colliders when the "game starts", meaning that OnTriggerEnter() won't be called at all because the objects start inside the colliders, and bounds.Contains() isn't very accurate.

Any ideas are appreciated, thank you for reading.

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image screenname_taken · Apr 29, 2015 at 07:46 AM 0
Share

And to expand on this, OnTriggerExit won't work for me if the object is teleported away while inside a trigger. Like going to a checkpoint.

avatar image Baste · Apr 29, 2015 at 08:14 AM 1
Share

You can figure out exactly how it works, Unity uses a version of PhysX to run the physics, and the source of the main project is on GitHub. Read info about that here.

Unity uses something called the Scene Graph to keep track of where things are in the game word. It's fairly complex, and replicating that will be a lot more work than what's probably viable.

If you just want to know how far some things are away from some other things, just check their distance. Have everything that you need to check register themselves to some static list, and check how far away each of those are from the collider. Remember that comparing the square distances you get from Vector3.sqr$$anonymous$$agnitude is faster than checking the distance itself.

avatar image boddole · Apr 29, 2015 at 08:22 AM 0
Share

@Baste:

Interesting, thanks for the heads up. In my case (with mesh colliders) distance isn't very relevant so for the moment I'm using colider.raycast() to check for intersections. If there is intersection, then the object is outside the collider. If no intersection occurs, the object should be inside the volume.

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make gameObject make only one collision 1 Answer

boost and hit the edge of a collider and you go backwards 0 Answers

How to have a score counter increment in OnTriggerEnter 1 Answer

Application.LoadLevel ("lower") loads on start-up, not when triggered; Deadline is soon HELP! 3 Answers

onEnterCollider returns Collider 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges