I looked for a similar post but couldn’t find any other problem like this. So here’s another collision issue for you…
I have a Box Collider that is a Trigger & a Rigidbody that is Kinematic attached to an object called “objA”. (objA is attached to the camera.)
I also have another object with a Sphere Collider that is NOT a trigger and a rigidbody that is NOT Kinematic attached to, which I call “Pizza”.
objA is very big and can encapsulate Pizza on collision. I added a print statement that prints the name of the collifing object on OnTriggerEnter and attached this to objA. (It prints many other objects’ names on enter once the objects enters. That’s working fine.)
My problem is:
However, when Pizza enters objA, the OnTriggerEnter event detects Pizza without stopping! Pizza is the only one that gets read countless times eventhough it never leaves the box after entering. So it enters the objA and stays there and I can see the print statement go crazy, running constantly!
How do I solve this problem? Why does this happen?
This can also happen if you have a CharacterController inside of a Trigger and are setting the CharacterController’s radius every frame.
I found the answer to my question and that was this line:
that I executed OnTriggerEnter. I’m guessing I was reactivating an object recurdively and upon REreactivation it enters the trigger again which causes an infinite loop.
Thanks for your time!
Could it be that you are misusing the collision functions.
OnTriggerEnter(other:Collider) means you don’t want the physics engine to interact. So the 2 objects will simply pass each other through, still you can make things happen.
Try using OnCollisionEnter(other:Collision) if you want to object to collide and bounce without passing through.
Now, you need to decide what you want to happen,do you want object to get through it or not. Do you only want the pizza to bounce? Your objA is trigger so the physics engine is off, IsKinematic also disables the rigidbody collider. Meaning you have there a zone more than an object. The console prints because it reports a collision on every frame, now you would have to define some more behaviours once the collision happens.
It also seems to happen if your collider vertices are edited on every frame (by a Deformer for example).