So a little info about the scene. I have a room that floods with water. The water is an object with a mesh collider (set as trigger) and a kinematic rigidbody) It spawns with the Y scale set to 0.01 and after spawning the fixedupdate will increase the y scale to simulate flooding.
the player has a child gameobject near its eyes which is a box collider also set as a trigger and with a kinematic rigidbody.
The idea is that when this box enters the meshcollider of the water the vision changes and the player starts to drown. So this child object has the following script attached:
Now the ontrigger enter fires off every time starting the player to drown. But when the player exits the body of water (either by jumping or just moving away) the ontrigger stay never fires.
Both rigidbodies are set to the lowest mass, no drag and with discrete collision detection. Both object are also in layers that have collision detection enabled.
I hope anybody can spot the flaw in my plan because I am stuck
OnTriggerStay is not meant to fire when exiting the trigger (not sure if you had a typo or not).
First, try with only enter and exit and see if it works for you.
Ah sorry that’s written a bit unclear, what I meant was only the ontriggerenter event gets triggered. Ontriggerexit and ontriggerstay both don’t. (the logic in the ontriggerstay function was mearly a quick copy paste for debug purposes)
Ive tried both mesh colliders and box colliders. I think the problem stems from the fact the body of water is being moved by manipulating scale. If I remove the script it seems to work.
I think I have the root of the problem. Both colliders have kinematic rigidbody’s. And according to the table found on this page:
They will not detect collision. So my new problem is, I just want to detect collision of an object with another object, they can’t influence the other object in any way. How would I do this without both of them being kinematic?
Edit I spoke to soon, even with only 1 of the rigidbodys kinematic only the entry gets registered.
Our solution in the end was to remove all meshes and fill each room with box colliders. Because the rooms are not cube shapes this was not the prefered way. But it gets the job done. Thanks for the additional info Ron!