- Home /
Exiting a collider while entering another giving wrong output
I have an enemy field of view script using OnTriggerEnter2D and OnTriggerExit2D setting a bool isSeen to true or false. I was doing testing overlapping colliders and found when I exited one immediately into another isSeen was set to false even though I was inside the collider. The colliders belong to two different gameobjects but send the output to the main player script.
I have tried using OnTriggerStay but the same result kept happening. Does anyone know of a fix for this, it woulkd be greatly apreciated
What collider are you entering after exiting ? Are they both attached to the enemy ?
Enemy, two capsule colliders, both colliders have the same script attached to them,I have an enemy, two capsule2D colliders each collider has the same script attached to it
Maybe its something in your game logic. Can you attach a screenshot of your code?
private void OnTriggerEnter2D(Collider2D collision) { if(collision.gameObject.tag == ("Player") {isSeen = true;} }
private void OnTriggerExit2D(Collider2D collision) { if(collision.gameObject.tag == ("Player") {isSeen = false;} }
There is other code that counts from zero to 100 while true but the actual true or false value is the issue. When exiting a collider it sets false but if I am in another collider it does not set to true
I tried OnColliderStay but because there are colliders that all have different scripts, one collider set it to false, but another set it to true and was overridden