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
0
Question by Despise452 · Aug 02, 2012 at 03:25 PM · rigidbodycollidertriggerontriggerenter

Rigidbody + Multiple Trigger Colliders - OnTriggerEnter - Get which Collider triggered the event issue

Good morning, unityAnswers. First time poster - I'll try to make myself clear.

I want a character in my game to have a cylindrical collision box with a rigidbody. With the only options similar to what I want being a BoxCollider or a CapsuleCollider, I'm trying to combine the two and using them as triggers - making the CapsuleCollider higher and lower than the height of the BoxCollider, thus the areas that collide with BOTH make out a cylinder.

OnTriggerEnter / Leave get called when either one or the other enters or leaves another CollisionBox, but the Collider object sent to these methods only holds information for the object hit by my character.

In no way have I been able to pull which of my two colliders triggered the event, which is necessary for me to track whether both are colliding at the same time.

I turn to you, Unity Community - as I have been using all your questions and answers frequently - to much aid.

Thank you all in advance, if further clarification is necessary, please ask and I'll do my best.

Cheers.

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Owen-Reynolds · Aug 02, 2012 at 04:00 PM

Anytime you need to check for collider contact, but can't do it in the enter function, you can have them set flags, so the triggers are recording your in/out status. Ex of cubeTriggerScript:

 bool inCube=false;

 OnTriggerEnter(..) { if(player) inCube=true; }
 OnTriggerExit(..) { if(player) inCube=false; }

Then do the same with, say, inCapsule and the capsule trigger.

But this gives up the advantage of Enter/Exit knowing we just now entered. To get that back, you need one more flag to remember if you were in or out last frame. You could then have Update check something like:

 bool inCyArea=false; // make sure I do stuff only the 1 frame I enter/exit
 
 if(!inCyArea) { // if I'm currently not in, did I just enter:
   if(inCube && inCapsule) { inCyArea=true; do enter area stuff }
 }
 else // I'm currently in, looking to get out:
   if(!inCube || !inCapsule) { inCyArea=false; do leave stuff }

More efficient is to move that from every-frame update to each enter/exit (which is the only time you need to check.) Ex:

 OnTriggerEnter(..) { if(player) { inCube=true; checkForNewEntExStatus(); } }

Of course, the two triggerAreas will have separate scripts for their Enter/Exits. That means you'll really be reaching all over the place for the variables, with things like boxScript.inCube instead of a simple inCube.

Comment
Add comment · Show 2 · Share
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 Despise452 · Aug 02, 2012 at 04:36 PM 0
Share

Hi Owen, thanks for your quick reply!

I understand what you mean, I was simply hoping there was a workaround that would allow me to monitor both of the collision boxes in the same script. It's a shame I can't.

However, since I've posted this question, I've created a cylinder mesh in Blender, and added it as a $$anonymous$$eshCollider - having some issues with it colliding with other object's colliders such as BoxColliders, but I'm working that out.

Thanks again for your input, if you have any other tips for a man in this situation, feel free to suggest!

Cheers.

avatar image Owen-Reynolds · Aug 02, 2012 at 04:50 PM 0
Share

The meshColliders now work surprisingly well. $$anonymous$$ake sure you check Convex (and don't go nuts on the poly count.)

I used the trick with bools to make a "shell" around something, which can't be done with a convex mesh.

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

7 People are following this question.

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

Related Questions

OnTriggerEnter not being called, have trigger, RB, and colliders set? 1 Answer

OnTriggerEnter/Exit called unexpectedly 2 Answers

Access other collider without use of Trigger collider. 1 Answer

Can't get trigger to work 1 Answer

OnTriggerEnter fails to activate 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