Grounded animation!

Hi, I got a character to play an Idle animation when it’s grounded. The only problem is that when I move it the Idle animation wont stop. If I take away the Idle animation the air animation still plays even when I’m grounded!

Here’s the script:

var animationRoot : Animation;

function Update ()
{
    var controller : CharacterController = GetComponent(CharacterController);
    if (controller.isGrounded)
    {
    print("Grounded");
    animationRoot.Play("Idle");
    }
    	else {
    animationRoot.Play("Jump");
    }
}

Any help will be great!

Thanks.

It looks like a bit of the old if else treatment might be needed. This works but havent tried it with animation yet. Let us know eh?

function Update () 
{ 
    var controller : CharacterController = GetComponent(CharacterController); 
    if (controller.isGrounded) 
    { 
    print("Grounded"); 
  
    } 
       else if (!controller.isGrounded) { 
    
        print(" NotGrounded"); 
    } 
}

HTH
AC

Thanks. I’ll try it tomorrow.

function Update ()
{
    var controller : CharacterController = GetComponent(CharacterController);

    if (controller.isGrounded)
    {
        print("Grounded");
    }
    else if (!controller.isGrounded)
    {
        print(" NotGrounded");
    }
}

Is exactly the same as:

function Update ()
{
    var controller : CharacterController = GetComponent(CharacterController);

    if (controller.isGrounded)
    {
        print("Grounded");
    }
    else
    {
        print(" NotGrounded");
    }
}

Printing not grounded is a good idea though. Another thing is it might be better to do it on an event basis, so that the animation is changed once when something happens, for example when the player lands instead of once per frame.

Thanks Yoggy, I had no idea.

This script works, but if you follow Yoggys lead, you can change it how u like:

function Update () 
{ 
    var controller : CharacterController = GetComponent(CharacterController); 
    if (controller.isGrounded) 
    { 
    print("Grounded"); 
    animation.Play("idle"); 
  
    } 
       else if (!controller.isGrounded) { 
    
        print(" NotGrounded"); 
        animation.Play("jump"); 
    } 
}

AC