Hi,
I have a capsule(the NPC body) with a cone mesh attached(their sight). This sight cone has attached a trigger collider and a kinematic rigidbody. This NPC is patrolling, so he walks and looks around. The problem is that I’m using another capsule(the player), which has both a collider(not trigger) and a kinematic rigidbody, to test the NPC sight(basically, I’m moving this character so to enter the field of view of the NPC), but OnTriggerEnter/Exit on the sight cone on the NPC is called unexpectedly: when the player capsule enters the trigger mesh of the NPC, suddenly onTriggerEnter and onTriggerExit get called twice each(and yes, in both onTriggerEnter and onTriggerExit i check that the object entering/leaving is the player collider). The same thing happens when the player collider leaves the trigger mesh of the NPC, onTriggerEnter and onTriggerExit get called twice each.
To make things a bit clearer, this appears in the Console:
Player Entering
Player Entering
Player Leaving
Player Leaving
Does anybody have any idea about what’s going on here?
Is it possible that the NPC sight mesh is intersecting with the NPC's capsule? You can do a quick check in the console like this: function OnTriggerEnter (col : Collider) { print(col.gameObject.name); }
– oneslyfoxunfortunately, i already checked, but no, that's not happening :\
– zhedThis might seem silly, but you don't have duplicates of the script on the object, do you? Other than that, I'm stumped.
– oneslyfoxI would filter out the collisions by making sure they are indeed the player. Use Tags or Layers or w/e you wish, but make sure the collider entering the trigger is what you think it is. Also add some simple print debugging like so: void OnTriggerEnter( Collider col ) { Debug.Log( col.gameObject.name + " is entering trigger " + this.gameObject.name ); } And the same for exit. That should tell you exactly what is going on, and should probably make the problem become obvious. Hope so anyways! Post with results if not!
– OP_tossAnother thought... Is your cone collider a mesh? If so, that could be causing the immediate enter/exit behavior, if it has bad normals, is not a closed object, convex is wrong, etc...
– OP_toss