Animated character error

I created a character with animations, walking from frame 1 to 60 and resting from frame 61 to 62. Then I have applied the following code but it doesn’t work.

function Update ()
{
   if (Input.GetAxis("Vertical") > 0.2)
       animation.CrossFade ("idle");
   else
      animation.CrossFade ("walk");
}

I leave screenshots of configurations:

Please is urgent!

What does it do?
Maybe try switching Idle mode to clamp forever.

The result is the same :(. I recorded a video which shows the problem.

Thank you for your help!

Uh… If you want your character to perform the walk animation when you press the “vertical” keys, shouldn’t your if statement say:

function Update ()
{
   if (Input.GetAxis("Vertical") > 0.2)
       animation.CrossFade ("walk");
   else
      animation.CrossFade ("idle");
}

(BTW, I use this code for my walk/run sequence)

if (Mathf.Abs(Input.GetAxis("Vertical")) > (0.2*(.5*scale)))
	  animation.CrossFade("walk");

//scale is my own variable for when I implement different scales for my character

Also did you initialize your animations in the Start function?

function Start ()
{

	controller = GetComponent(CharacterController); 
	animation.wrapMode = WrapMode.Loop;
	
	animation["jump"].layer = 10;
	animation["jump"].wrapMode = WrapMode.ClampForever;
	
	animation["fall"].layer = 10;
	animation["fall"].wrapMode = WrapMode.ClampForever;
	
	animation["land"].layer = 10;
	animation["land"].wrapMode = WrapMode.Once;
	
	animation.Stop();
	animation.Play("idle");
}

I didn’t initialize my animation in the Start function? How can I do it? I’m a noob in character animation.

Thank you for your help!!!

First try switching the walk and idle animations in your if statement (Seen above), and if you still start walking when you start, add this:

function Start()
{
animation.Stop();
animation.Play("idle");
}

It doesn’t work TT. I have put all the thinks you said. I leave another video with all the configurations.

How about putting your animation “idle” as element 0 for your animations and walk as element 1 for your animations.
Animation tab → Element 0 = walk atm (word of advice, idle should always be your first animation)

Also double check that idle is spelt the same in all scripts (no “Idle” and “idle” it’s case sensitive) Also have this instead for start:

function Start ()
{

	controller = GetComponent(CharacterController); 
	animation.wrapMode = WrapMode.Loop;
	
	animation.Stop();
	animation.Play("idle");
}

Ok, I put walk as element 1 and idle (well spelt) as element 0. Then I put idle as the object of Animation (see the video) in the Player and in the Character. Now plays idle when start but it doesn’t walk.

Ok, that means we’re getting somewhere. Now, for your walking, is that controller relating itself to “Vertical”? Like if you were to push the WASD or arrow keys? If not then your problem is stemming from there (meaning vertical isn’t being used when you’re calling an if statement for it), second, use Mathf.Abs instead:

if (Mathf.Abs(Input.GetAxis("Vertical")) > 0.2)
	  animation.CrossFade("walk");

It doesn’t work :frowning: No, only I want is when the LeftJoystick (Move Joystick) is moved, player starts walking.

Start with the WASD/arrow keys, and then work your way towards that left joystick’s movement, I think you jumped too far ahead making that joystick. Also if your animations with with WASD/arrow keys, it means that your joystick is having the problem and not your animation script.

Well, I can’t start with WASD/arrow keys because this game is developed for iOS platform so the joysticks are Unity’s default items.