- Home /
best way to determine if a character is grounded?
I'm making a 3d platformer game and I managed to code a double jump that kind of works, I'm using OnCollisionEnter and OnCollisionStay to determine if my character is grounded, it works alright but the problem is that if my character hits the ceiling with its head or the walls with any of the sides of its collider my code automatically assumes the character is grounded and allows it to jump indefinitely!
is there any way to make the OnCollisionEnter and OnCollisionStay functions to detect when it's colliding with only the lower part of my character's collider?
Thanks!
You could use the Layer Collision $$anonymous$$atrix This will let you choose to ignore the collisions between certain tags.
Or you could tag the objects were you would allow double jump.
function OnCollisionEnter (other : Collision)
{
if(other.gameObject.CompareTag("Grounded"))
{
gameObject.GetComponent(NameOfDoubleJumpScript).enabled = true
}
}
Answer by Cherno · Aug 20, 2014 at 01:28 PM
Take a look at this comprehensive tutorial:
https://www.packtpub.com/books/content/unity-3x-scripting-character-controller-versus-rigidbody
It shows how to deal with the ceiling issue by pushing the cahracter away from it before the jump zenit is reached.
Answer by el-RERS · Aug 20, 2014 at 06:20 PM
I just tried with a combination of OnCollisionEnter AND raycasts, seems to be working fine for now! but let's see in the future, thank you so much guys! :D
Your answer
![](https://koobas.hobune.stream/wayback/20220613161044im_/https://answers.unity.com/themes/thub/images/avi.jpg)