- Home /
unity 5 on trigger exit bug
Ive tried every possible combination of colliders and ridigidbodys but this just does not work it will sometimes just keep the bool true why does it do this and what can i do to work around it
void OnTriggerEnter(Collider collisionInfo) {
if (collisionInfo.gameObject.tag == "Water") {
inWater = true;
}
}
void OnTriggerExit(Collider collisionInfo) {
if (collisionInfo.gameObject.tag == "Water") {
inWater = false;
}
}
Sorry if you already tried this, but did you set something like
void OnTriggerEnter(Collider collisionInfo) {
if (collisionInfo.gameObject.tag == "Water") {
inWater = true;
Debug.Log ("Entered Water");
}
}
void OnTriggerExit(Collider collisionInfo) {
if (collisionInfo.gameObject.tag == "Water") {
inWater = false;
Debug.Log ("Exited Water");
}
}
These debugs will pop up in your console telling you if your trigger is even working.
I would also try this. I also had tons of problems with triggers, but This is what has been working for me. remove the gameObject and just search for the tag
void OnTriggerExit(Collider other)
{
if (other.tag == "Water")
{
inWater = false;
Debug.Log ("Exit trigger");
}
}
Also make sure that what your trying to collide with is tagged "Water".
https://www.youtube.com/watch?v=e$$anonymous$$pGFtubrP8 heres a video showing it. as you can see it only works sometimes
Is your character movement script using CharacterController.$$anonymous$$ove, or is it using Transform to move the player?
If you believe you've found a bug, you should create a $$anonymous$$imal project that reproduces the problem and submit it via Help -> Report a Bug.
Answer by LinkoVitch · Jun 13, 2015 at 11:43 AM
Possibly a horrible hack, put perhaps use a combination of OnTriggerStay and LateUpdate?
In the OnTriggerStay test for water and set inWater to true as you are doing. Then in a LateUpdate reset it back to false. As I say, not the most eligant sollution but hopefully something that might work around your current issue.
I wonder if the issue you are seeing is due to the collider moving out of the water and back in within the same update and confusing the collision system? Is your player movement being done within Update or FixedUpdate?
the movement is done in fixed update Could this be the problem?
hmm no having it in Update makes it worse and not call triggerexit at all
the lateupdate hack works. is there any problems i may run into using it?
I was thinking if you were already doing it in Update that moving it to FixedUpdate may work. Unfortunate that it wasn't the case, but I think it proves the issue is to do with the ti$$anonymous$$g of the collision.
I have no idea if long term the hack will cause further problems, sorry.
Just wondering, is the collider for the water mapped to the rippling surface of the water? If it is, perhaps make the collider a simple box collider just below the animated surface, I am guessing that as you leave the water and OnTriggerExit occurs, that perhaps the surface of the water is then moving and cancelling the exit. Does sound like unintended behaviour to me.
HTH
na its a simple box collider set to trigger so really not sure why it does this
Your answer
Follow this Question
Related Questions
Can't click gameobject when over another trigger? 1 Answer
Multiple animation with One Trigger ?!! 1 Answer
How do you make a trig object? 0 Answers
how to get collision to control servo motors 1 Answer
Unity Trigger 2D not working 0 Answers