sebastienlachance
1/28/2015 - 5:22 PM

IsGroundedFrom http://answers.unity3d.com/questions/196381/how-do-i-check-if-my-rigidbody-player-is-grounded.html

var distToGround: float;
 
 function Start(){
   // get the distance to ground
   distToGround = collider.bounds.extents.y;
 }
 
 function IsGrounded(): boolean {
   return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
 }
 
 function Update () {
   if (Input.GetKeyDown(KeyCode.Space) && IsGrounded()){
     rigidbody.velocity.y = jumpSpeed;
   }