Hey guys, you’re the best on here btw, all my other questions have been answered
But not this one! Can’t find anything on this one anywhere…
My issue, I have triggers very close to one another, the player object hits the first trigger fine, but then when approaching the next trigger, there is a point where the player object is triggering both triggers…
Is there a way to have only 1 trigger at a time? Even when the Player Object is on both triggers, is there a way to have unity recognize the single trigger that the player is “mostly on” and ignore the other trigger, even though the player object is still technically touching both?
Because right now I have the issue where, obviously, both triggers engage at the same time, I just want the single dominant trigger.
I would place the triggers further apart if possible, but then I always have a little spot where no trigger is active, or a little spot where both are active - I cannot get a smooth transition this way… I really need the seamless transition from one to the next, without the “dead spot” - I believe allowing only a single trigger at a time would provide a more seamless switch from one to the next without always having both active
Thanks guys!
I don’t know what your actual use case is, but I can think of the following:
- OnTriggerEnter, save the current collider to a Dictionary of collision objects and their callstate (explained later)
- OnTriggerExit remove it from the dictionary
- For any object entering your trigger, add it to that dictionary. If there’s already one more entry, DO NOT CALL your code. If the other(s) leave the Dictionary and the number goes down to just that one CALL your code and set its callstate to true
This effectively means, you know who comes, who leaves and WHEN to call just ONCE for a CURRENT object. with the dictionary you are able to avoid calling twice on an object you triggered while triggering and leaving multiple adjacent objects.
If your game does not have branches in it, I guess a list would suffice
Alright we figured this out in a more simplified manner. I’m certain haxagonius’s answer would also work, but we were unable to get the list and dictionary to function properly - but that’s more our fault than anything else.
The solution we’re implementing is so simple it’s a bit silly. We added a bit of code to deactivate the surrounding colliders when a collider is activated - so as one collider is triggered - the surrounding colliders are disabled - when moving to another - that collider is activated and the surrounding colliders to that collider are deactivated - resulting in only 1 collider active at a time.