Advertisement

OnTriggerExit Activates when you exit a collider even though you are still colliding with the other collider

Started by August 02, 2022 12:32 PM
4 comments, last by Ripac 2 years, 4 months ago

Hey guys. I am making a TD game and I've decided to not use a grid system. I am spawning objects with just drag and drop with colliders. There is only one problem. Everything works fine but when there is a spawned turret near the enemies' path and I drag the new object across both of the colliders(the collider for the path and for the spawned turret) The color for indicating whether you can or cannot spawn the turret there, is glitching. I know why it happens but I don't know how to fix it. Basically, the "OnTriggerExit" activates for a second when I leave the path collider even though I am still in the turret's collider. Can someone please help me with this? I will try to upload a short clip to show you what I am talking about.

Video for more info: https://streamable.com/nwvhjb

The problem is in the transition from a collider to a different collider.
The OnColliderExit activates every time it leaves a collider no matter if it still collides with another object.
The code that I showed you works fine.
The only problem is the color the color changes for a second every time it exits a collider but the turret cannot be spawned there.

Isn't that by design? I've come to expect OnTriggerExit to mean “I have exited this one specific trigger", not “I am no longer in contact with ANY trigger.”

Perhaps you could deal with this by having your behaviour track how many triggers it is currently in, if Unity doesn't already provide that?

Advertisement

@Oberon_Command I am not sure how to track the number of objects it's colliding with.

Ripac said:

@Oberon_Command I am not sure how to track the number of objects it's colliding with.

I was thinking you could, for instance, have a counter that you increment in OnTriggerEnter and decrement in OnTriggerExit.

@Oberon_Command Yeah, I understood what you are saying. Thank you so much!

This topic is closed to new replies.

Advertisement