animation script for 2D platformer issue

Hi! im not able to make other animations to loop, i have already checked loop Time and Loop
Pose boxes, i think it is somthing i did wrong with my code. For example when i want my character to walk the animation gos for 0.2 or so sec and then stops and goes to idle.

code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class character_mov : MonoBehaviour
{
    private CharacterController controller;

    private float verticalvelocity;
    private float gravity = 17.0f;
    private float jumpforce = 20.0f;
    private float characterspeed = 18.0f;
    private Animator Char_anim;

    
    void Start()
    {
        controller = GetComponent<CharacterController>();
        Char_anim = GetComponent<Animator>();
    }

    
    void Update()
    {
        if (controller.isGrounded)
        {

            verticalvelocity = -gravity * 2 * (Time.deltaTime);
            if (Input.GetKeyDown(KeyCode.LeftAlt))
            {
                verticalvelocity = jumpforce;
                Char_anim.SetTrigger("is_jumping");
            }



        }
        else
        {

            verticalvelocity -= gravity * 3 * Time.deltaTime;
        }
        Vector2 moveVector = Vector2.zero;
        moveVector.x = Input.GetAxis("Horizontal") * characterspeed;
        moveVector.y = verticalvelocity;
        controller.Move(moveVector * Time.deltaTime);
        

        if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.RightArrow))
        {
            Char_anim.SetBool("is_walking", true);
            Char_anim.SetBool("is_idle", false);
        }
        else
        {
            Char_anim.SetBool("is_walking", false);
            Char_anim.SetBool("is_idle", true);
        }
          
    }
}

GetKeyDown is only called once, right at the start of when you press a key. Every other frame your else is running setting is_walking to false. Change GetKeyDown to GetKey and it should give you a better result.

Thank you! Works fine now :slight_smile: