Landing Problem

How can i say if the character landing or if the character landing By the Gravity Of the RigidBody? To play an animation :smiley:

  • Add a collider to the thing you are landing on
  • Write a collision test in OnCollisionEnter and check for the ground collider
  • If you are hitting the ground, check your velocity magnitude. Presuming this is a land not a bounce:
  • Play your animation with animation.Play(“YourAnimationName”);

If you want to play different animations when landing after a jump and when falling from somewhere, you must use a boolean flag - like jumping, for instance - to remember if the character was jumping:

var jumping: boolean = false;

function Update(){
  if (Input.GetButtonDown("Jump")){
    jumping = true;
    // jump code here
  }
}

function OnCollisionEnter(col: Collision){
  if (col.gameObject.tag == "Ground"){ // when landing on the ground...
    if (jumping){ // remember if it was a jump...
      // character was jumping
    } else { // or a fall:
      // character falling
    }
    jumping = false; // clear jumping anyway when landing
  }
}

NOTE: If you need to detect when the character starts falling, check if it’s not grounded && rigidbody.velocity.y is negative - if both are true, the character is falling.