- Home /
Question by
Gamer206 · Jul 25, 2017 at 11:33 AM ·
rigidbodygroundedground detection
How do I check if my player is grounded with physics?
I try to make player jump with Rigidbody but it doesn't work.
checkCollider = Physics.OverlapSphere(groundCheck.position, groundRadius, groundLayer) // a collider with its parameters
if(checkCollider.Lenght > 0) {
isGrounded = true;
} else {
IsGrounded = false:
}
if(Input.GetKey (KeyCode.Space) && isGrounded) {
GetComponent<Rigidbody>().velocity = (GetComponent<Rigidbody>().velocity.x, jumpSpeed, GetComponent<Rigidbody>().velocity.z);
// I have the jumpSpeed variable
Comment
Best Answer
Answer by DavoBlackOut · Jul 25, 2017 at 07:12 PM
float DisstanceToTheGround = GetComponent<Collider>().bounds.extents.y;
bool IsGrounded = Physics.Raycast(transform.position, Vector3.down, DisstanceToTheGround + 0.1f);