Can't detect isgrounded? Help

I am working on movement animations and my walk animation still plays if i am falling and i press w or s. How can i make a var isgrounded be true when i’m on the floor? I am not using the character controller… Here is my animation script with my attempt at a isgrounded detection.

var isMoving : boolean;
var isgrounded : boolean = false;
var isSprinting : boolean;

function OnCollisionEnter(col : Collision) {
    if (col.gameObject.tag == "floor") {
        isgrounded = true;
    }
}


function Update () {

if (Input.GetKey("w") || Input.GetKey("s"))
{
 
	isMoving = true;
 
 animation.CrossFade ("walk");
    } else {
    
 isMoving = false;
 animation.CrossFade("idle");
       }


if (Input.GetKey("a"))
{
 

 
 animation.CrossFade ("strafeLeft");
   }

if (Input.GetKey("d"))
{
 

 
 animation.CrossFade ("strafeRight");
   }


if (Input.GetKey("left shift") && isMoving)
{
 
	isSprinting = true;
 
 animation.CrossFade ("run");
   }
}

1 Answer

1

if ((Input.GetKey(“w”) || Input.GetKey(“s”)) && isGrounded)
{
}

i cant get isgrounded detection

–

I'm using the same code in my character controller (in c# though) and it works fine. It doesn't look like you are checking if your character isGrounded anywhere in your script. If isGrounded isn't changing when you land on the floor, then you either misspelled the tag (capitalization is important) or you forgot to tag your floor.

–