• 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 SerWind · Jan 20, 2014 at 01:34 AM · c#collisioncollider

OnCollisionExit or OnTriggerExit with Physics.IgnoreCollision

I must be missing how these two things work. Right now I have a border made out of objects slightly off screen so when a bouncing ball hits them it changes direction randomly. I want the ball to spawn outside and move in.

Physics.IgnoreCollision gets set to true but it's in OnCollisionEnter.

OnCollisionExit or OnTriggerExit are never called when the ball passes through, which is how I thought they were suppose to work. My assumption is that because it is now ignoring physics with that object it no longer calls either of these functions and so I can't use them to change Physics.IgnoreCollision to false.

My question is two fold:

Is that true?

If so, what else can I do?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MoMughal · Oct 26, 2018 at 02:03 PM

I also got this issue and one neat way to resolve it is to do in Coroutine like the following

private IEnumerator WaitForIgnoreCollision(GameObject a, GameObject b) { Physics.IgnoreCollision(a.collider, b.collider, true); yield return new WaitForSeconds(5f); Physics.IgnoreCollision(a.collider, b.collider, false); }

and then call it in the OnCollisionEnter at whatever condition you might need it at.

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

Answer by joedartjr · Jan 20, 2014 at 01:58 AM

Triggers and Colliders are one-way; like mesh textures. If you are on the "inside" of one, then the collision will not hit. There aren't enough details about where your colliders are at to know if this is the case.

Also, if the ball is a Rigidbody and you are trying to use a Trigger, then the ball has to be set to Kinematic for the trigger to take effect; conversely, if you are using colliders, then the collider cannot be labeled as a Trigger.

Hopefully something from this can point you in the right direction. If not, more details never hurt anyone, or a screenshot of how your border is setup.

Comment
Add comment · Show 4 · 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 SerWind · Jan 20, 2014 at 02:03 AM 0
Share

I know it's not the prettiest border, I'm not too concerned about cleaning it up just yet. The ball spawns anywhere outside and goes through it but then OnTriggerExit is never called even when the ball is set to kinematic (it is using a rigidbody).

Am I missing something about triggers? Are they specific objects or can they just be any object with a collider?

Forgot the image. alt text

ss (2014-01-19 at 10.01.59).png (8.7 kB)
avatar image joedartjr · Jan 20, 2014 at 02:25 AM 0
Share

If you have the ball set to $$anonymous$$inematic, then you will need to set the border objects to "Is Trigger"; just know that while the "collision" between a kinematic rigidbody and a trigger happens, you get no visible collision. Do you have a Debug.Log attached to the OnTriggerExit?

If your OnCollisionEnter is hitting properly, and causing the Physics.IgnoreCollision to properly activate then you are preventing any further collisions from happening by disabling them.

The easiest solution is to increase the size of one of your borders so that the ball will start inside of it, then you shouldn't need to worry about changing the Physics.IgnoreCollison flag at all, since the collision only happens one-way. Simply leave it enabled, and start the ball from inside the collision zone; this should allow the ball to come out of the border, but not re-enter it.

Another solution is to have the IgnoreCollision flag to be reset after a set amount of time.

 public float enableCollision = 5f;
 
 void Update
 {
 if (Physics.IgnoreCollision == true)
 {
 enableCollision -= Time.deltaTime;
 }
 if (enableCollision <= 0)
 {
 Physics.IgnoreCollision = false;
 }
 }

Something like that.

avatar image SerWind · Jan 20, 2014 at 03:46 AM 0
Share

That's a really good idea actually. I was about to try it. Removed the code that caused the physics collision ignore, rebuilt, ran it. Still going through...

Closed unity, restarted. Rebuilt. Still going through. I have looked over my code and I have no idea why it's still doing that. This is very frustrating.

avatar image SerWind · Jan 20, 2014 at 04:47 AM 0
Share

It turns out I had kinematic on. That works for the most part but the border it spawns in it goes back through for some reason.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

20 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

Related Questions

ParticleSystem collision checking. 2 Answers

Fist Punch Collision 0 Answers

How to perform one pass collision detection on many objects? 2 Answers

Getting a sword in place while attacking an enemy 3 Answers

How to collide with NGUI element? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges