- Home /
Setting a bool to false using CharacterControllerHit?
I want to decide if the player is grounded or not without using the (charachterController.isGrounded) function. I have this bit:
void OnControllerColliderHit(ControllerColliderHit hit)
{
if (hit.transform.tag == "Ground")
{
isGrounded = true;
}
}
Is there a way to set "isGrounded" to false if the player stops touching a collider tagged "Ground"? Everything is working as intended, except for the lack of a "OnExit-like" function. * How do I set "isGrounded" to false in this case?
Answer by wewewu · Jun 09, 2020 at 05:21 AM
Try to use OnCollisionEnter, OnCollisionExit and OnCollisionStay
For some reason, these didn't work. I have no idea why, they should've worked. I tried so hard to find an error but there were none. I'm quite new to coding, so I suppose there's a function or such that I'm not aware of. Based on what these sound like, OnCollisionEnter, the boolean should "trigger" on collision with the object tagged "Ground", but even so, they didn't work.
Your answer
![](https://koobas.hobune.stream/wayback/20220613000432im_/https://answers.unity.com/themes/thub/images/avi.jpg)