The player object has a gameobject with a small collider cube (set as trigger) at eye height. The following script is attached to that object:
// Use this for initialization
void OnTriggerEnter(Collider trigger ) {
if (trigger.gameObject.tag == "flooder" && !playerStats.m_headUnderWater){
Debug.Log("head under water");
playerStats.toggleUnderWater(true);
}
}
void OnTriggerExit(Collider trigger) {
Debug.Log("LeftTrigger!!!");
Debug.Log(trigger.gameObject.tag);
Debug.Log(trigger);
if (trigger.gameObject.tag == "flooder"){
Debug.Log("head left water");
playerStats.toggleUnderWater(false);
}
}
This is supposed to detect if a players head is underwater to trigger drowning.
The on trigger enter works fine, but on trigger exit will never register (not even the debug statements)
The body of water has a kinematic rigid body and a mesh collider set (also with trigger = true) to make collision possible and they are both in a layer that detects collision with the other layer. Tried setting the rigid body collision detection to continuous but even that did nothing.
Any help is appreciated!
hi try using trigger.collider.tag and try removing
– deltamishif (trigger.gameObject.tag == "flooder"){in OnTriggerExit and just use playerStats.toggleUnderWater(false);Not even the debugs get printed, so it's not in the if statement
– nopogowatch your collider of water when you jump out - maybe you are draging colider with you - maybe you delete the colider - maybe you make water false before you get out I don't know how other scripts go - do you really jump out or just swim to the surface? - what happens if it's not kinematic? it shouldn't move anyway as it's trigger so collider never colides because it's trigger so does not listenes to forces I think
– sdgdSo after watching the collider it is not reacting to the impact with the player. The collider is definitely there. Switching kinematic changes nothing. The water rises with 0.01 each fixed update. But so slow that after the head "submerges" a jump clears the collider box from the collider mesh of the water. I also tried adding oncollisionenter,exit, stay and ontrigger stay. Nothing gets printed/triggered after ontriggerenter :(
– nopogoahhh ok that's simple now IF nothing happens after ontrigger enter and this should prove me right: do an : void Update(){ Debug.Log("Updating"); } and after OnTriggerEnter(){} you should not recive any updating debug any longer somewhere else happenes that you disable this script OR delete this GameObject I don't know what kind of code you have in water or something that access water OR player/head script
– sdgd