- Home /
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");
}
}
Answer by electricsauce · Apr 03, 2013 at 12:24 AM
if ((Input.GetKey("w") || Input.GetKey("s")) && isGrounded) { }
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.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Trying to animate on collision, Help Please. 0 Answers
Analysing player metrics help 0 Answers
A node in a childnode? 1 Answer
On Collision, Create a Cube? 1 Answer