Question by
Doctor_Game9 · Mar 24 at 03:56 PM ·
c#tutorialgroundedground detection
Why isn't this Ground Check system working?
I followed a tutorial by Code Monkey on YouTube on how to make a ground check system but for some reason it always returns null. Tutorial: https://www.youtube.com/watch?v=c3iEl5AwUF8
And here's the ground check system:
private bool IsGrounded() // Check if the player is grounded
{
float extraHeightText = 0.01f;
RaycastHit2D raycastHit = Physics2D.Raycast(collider.bounds.center, Vector2.down, collider.bounds.extents.y + extraHeightText, platformLayerMask); // Do a raycast to see if the player is on the ground
Color rayColor;
if (raycastHit.collider != null)
{
rayColor = Color.green;
}
else
{
rayColor = Color.red;
}
Debug.DrawRay(collider.bounds.center, Vector2.down * (collider.bounds.extents.y + extraHeightText), rayColor);
Debug.Log(raycastHit.collider);
return raycastHit.collider != null;
}
Comment