I am trying to do the following:
I’ve got an enemy with a sensor that stops walking when it enters a trigger of a destructible wall. It then starts to attack. When the wall’s health is 0 I want the enemy to start walking again. So far so good…on paper.
OnTriggerEnter makes the enemy stop walking, OnTriggerStay makes the enemy attack, OnTriggerExit should make the enemy start walking again.
The issue I am getting though is that the OnTriggerExit of enemy sensor is never triggered. When I “get rid” of the wall (by setting it to a layer that has no collision with the enemy or destroy it) the enemy stills says it is stuck in the wall trigger according to the debug.log. When I animate the wall to move the enemy will start moving again until it hits the wall’s new position. Moving it a gazillion units away from its current position, as suggested in other threads, doesn’t really seem like a nice sollution, right?
I am getting the feeling as if getting rid of the wall, while the enemy’s sensor is static, doesn’t properly trigger the OnTriggerExit as I’d expect.
Another similar issue occurs where I have a sentrygun shoot when an enemy enters its trigger. Everything works perfectly but as the enemy is destroyed in the trigger, the sentrygun never gets the OnTriggerExit which results in a sentrygun that keeps on firing as if there is no tomorrow.
Any ideas what I am missing here? I am using C# by the way. This is the script that is attached to the enemy sensor.
void OnTriggerEnter (Collider other)
walk = false;
void OnTriggerStay (Collider other)
other.gameObject.SendMessage("ChangeHealth", damage * Time.deltaTime, SendMessageOptions.DontRequireReceiver);
Debug.Log("collide with destructible");
void OnTriggerExit (Collider other)
walk = true;