- Home /
OnTriggerEnter and Exit triggering simultaneously constantly
I have a NavMeshAgent (Enemy) that patrols around. it has two colliders one on the parent and one on the child. One much larger that the other. the child collider is use to see if the player is in range to be chased and the parent collider is to see if it is range to attack the player. The child collider OnTriggerEnter/Exit/Stay gets triggered appropriately but the Parent Collider triggers OnTriggerEnter/Exit simultaneously and constantly when the player is in the parents collider.
When i select the IsKinematic box on the rigidbody of the parent this problem is solved and OnTriggerEnter/Exit gets triggered at the correct times. the problem is that i would like to apply forces to my enemy and IsKinematic removes that option. Any idea why turning on isKinematic solves this problem? and is there a solution to this?
Answer by NEGATIVERAGDOLL · May 19, 2018 at 12:51 PM
Instead of using triggers you might want to look into using Vectors, it is a lot easier and usually works a lot better. For example you could use something like
if (Vector3.Distance(other.position, Player.position) <= 10) other is the object and player is the player. It will check the distance between you and the enemy object, if it equals 10 or below ("<" means below) whatever you want to happen can happen. You can then do the reverse for if you're a certain distance away.
Thanks for the help, I think your approach should fix the problem.
No problem, if you need anymore help don't hesitate to ask :)
Answer by jonnydredd · May 20, 2018 at 03:26 AM
No idea about why Kinematic would cause this, but I'm pretty sure swapping the colliders would solve this, as in, put the smaller collider on the parent and the larger chase box on the child. It seems like if the parent is triggered then it triggers the child too? Perhaps another method would be to have no collision on the parent, but have two children, one for chase box one for close collision, so they are called separately, without considering each other.
Answer by Guynelk · Feb 12, 2020 at 04:00 PM
Triggerstay and triggerexit will work simultaneously if you have a rigidbody to the parent and child. I had the same problem and when I deleted the parent's rigidbody, the collisions in child whose collision I wanted to detect worked correctly. I don't know if it will work for you but I took several days or even a week to find out
Your answer
![](https://koobas.hobune.stream/wayback/20220612163001im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
A child component is triggering its parent collider. 1 Answer
Why my "Is Trigger" box colliders are physically colliding with other colliders? 1 Answer
Does OnTriggerStay ignore layers? 1 Answer
Problem with multiple colliders in a trigger 2 Answers
Unity's collision system VS designing my own basic collision system 0 Answers