Animations do not perform

In my game I have 3 animations, idle, walk and jump. I prepared them in Maya and exported to Unity in the form Character@idle, Character@walk, Character@jump. They show OK in the Inspector. I put idle as my reference and dragged Character@idle to the scene. I added all the required elements in the Hierarchy and the Inspector, and selected the 3 animations there.
When I hit Play the idle is performed by the Character but when I move it I get a sliding movement of the Character (i.e. it do not performs the walk cycle)

Any help?

Without seeing any code that you’re using it’s hard to narrow down the issue. However my first port of call would be to check that it’s even calling the idle animation as the animation portion of the inspector will generally play idle by default.

I would change the animation that it’s calling to either jump or walk. If it’s playing the animation to begin with automatically it means that it’s having trouble calling anything. I’m hardly a pro coder but if you post the code you’re using to call it I’ll have a look-see :slight_smile:

This is the code. Nothing original. It is an adaptation of Penelope game script.
Thanks for your interest in helping me to solve this problem.

//////////////////////////////////////////////////////////////
// AnimationController.js
//
//
// AnimationController plays the appropriate animations
// and the blending between them. It uses the character’s
// movement direction to determine which animation should be played.
//////////////////////////////////////////////////////////////

// The Animation component that this script controls
var animationTarget : Animation;

// Different speeds depending on movement direction
var maxForwardSpeed : float = 6;
var maxBackwardSpeed : float = 3;
var maxSidestepSpeed : float = 4;

private var character : CharacterController;
private var thisTransform : Transform;
private var jumping : boolean = false;
private var minUpwardSpeed = 2;

function Start()
{
// Cache component lookup at startup instead of doing this every frame
character = GetComponent( CharacterController );
thisTransform = transform;

// Set up animation settings that aren't configurable from the editor
animationTarget.wrapMode = WrapMode.Loop;
animationTarget[ "jump" ].wrapMode = WrapMode.ClampForever;
//animationTarget[ "jump-land" ].wrapMode = WrapMode.ClampForever;
//animationTarget[ "run-land" ].wrapMode = WrapMode.ClampForever;
//animationTarget[ "LOSE" ].wrapMode = WrapMode.ClampForever;

}

function OnEndGame()
{
// Don’t update animations when the game has ended
this.enabled = false;
}

function Update()
{
var characterVelocity = character.velocity;

// When monitoring movement we check horizontal and vertical movement 
// separately to decide what animations to play.
var horizontalVelocity : Vector3 = characterVelocity;
horizontalVelocity.y = 0; // ignore any vertical movement
var speed = horizontalVelocity.magnitude;

var upwardsMotion = Vector3.Dot( thisTransform.up, characterVelocity );

if ( !character.isGrounded && upwardsMotion > minUpwardSpeed )
	jumping = true;

/*
if ( animationTarget.IsPlaying( "run-land" )
	&& animationTarget[ "run-land" ].normalizedTime < 1.0
	&& speed > 0 )
{
	// Let this animation finish
}
else if ( animationTarget.IsPlaying( "jump-land" ) )
{
	// Let this animations finish
	if ( animationTarget[ "jump-land" ].normalizedTime >= 1.0 )
		// when the animation is done playing, go back to idle
		animationTarget.Play( "idle" );		
}
else */if ( jumping )
{
	if ( character.isGrounded )
	{
		/*
		// play the appropriate animation for landing depending on
		// whether we are landing while running or jumping in-place 
		if ( speed > 0 )
			animationTarget.Play( "run-land" );
		else	
			animationTarget.Play( "jump-land" );
		*/
		jumping = false;				
	}
	else
		animationTarget.Play( "jump" );
}
else if ( speed > 0 )
{
	var forwardMotion = Vector3.Dot( thisTransform.forward, horizontalVelocity );
	var sidewaysMotion = Vector3.Dot( thisTransform.right, horizontalVelocity );
	var t = 0.0;
	
	// Use the largest movement direction to determine which animations to play
	if ( Mathf.Abs( forwardMotion ) > Mathf.Abs( sidewaysMotion ) )
	{
		if ( forwardMotion > 0 )
		{
			// Adjust the animation speed to match with how fast the
			// character is moving forward
			t = Mathf.Clamp( Mathf.Abs( speed / maxForwardSpeed ), 0, maxForwardSpeed );
			//animationTarget[ "run" ].speed = Mathf.Lerp( 0.25, 1, t );
			animationTarget[ "walk" ].speed = Mathf.Lerp( 0.25, 1, t );
									
			if (/* animationTarget.IsPlaying( "run-land" ) || */animationTarget.IsPlaying( "idle" ) )
				// Don't blend coming from a land, just play
				//animationTarget.Play( "run" );
				animationTarget.Play( "walk" ); 
			else
				//animationTarget.CrossFade( "run" );
				animationTarget.CrossFade( "walk" );
		}
		else
		{
			// Adjust the animation speed to match with how fast the
			// character is moving backward
			t = Mathf.Clamp( Mathf.Abs( speed / maxBackwardSpeed ), 0, maxBackwardSpeed );
			
			/*
			animationTarget[ "runback" ].speed = Mathf.Lerp( 0.25, 1, t );
			animationTarget.CrossFade( "runback" );
			*/
			animationTarget[ "walk" ].speed = Mathf.Lerp( 0.25, 1, t );
			animationTarget.CrossFade( "walk" );	
		}
	}
	else
	{
		// Adjust the animation speed to match with how fast the
		// character is side-stepping			
		t = Mathf.Clamp( Mathf.Abs( speed / maxSidestepSpeed ), 0, maxSidestepSpeed );

		if ( sidewaysMotion > 0 )
		{
			/*
			animationTarget[ "runright" ].speed = Mathf.Lerp( 0.25, 1, t );
			animationTarget.CrossFade( "runright" );
			*/
			animationTarget[ "walk" ].speed = Mathf.Lerp( 0.25, 1, t );
			animationTarget.CrossFade( "walk" );				
		}
		else
		{
			/*
			animationTarget[ "runleft" ].speed = Mathf.Lerp( 0.25, 1, t );
			animationTarget.CrossFade( "runleft" );
			*/
			animationTarget[ "walk" ].speed = Mathf.Lerp( 0.25, 1, t );
			animationTarget.CrossFade( "walk" );
		}
	}
}
else
	// Play the idle animation by default
	animationTarget.CrossFade( "idle" );

}

Hmm… is there any special variables that you need to consider for the animations? (eg. animation speeds altering or whatnot) as if it’s just a standard call to animation you could look at the project I’m working on at the moment is using this method to call animations:

if (!animation.IsPlaying(AnimationName.name)){
animation.Play(AnimationBane.name);

(So basically if it’s not playing that animation, begin to play it)

and for actions that the animation need to finish before they continue, yield the animation script so it holds until the animation is finished:

yield WaitForSeconds (AnimationName.length);

With my project however the animations are set to AnimationClip variables set up on the code so if your animations are called in a different way you should be able to work a method to adapt it so it works for you.

Finally I noticed that I was dragging the Character from the Project window instead of
dragging him from the Hierarchy window to the animation reference field in
the AnimationController script AND in the AnimationSpeed script . THAT WAS
THE ERROR!!! In the respective item into the hierarchy is where one works
adding components to it and therefore, this is the item that have all
the parts (including the animation list) that content the wanted properties.
SOLVED!