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");
}
}
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.