P
P
piffo2020-10-25 01:39:21
C++ / C#
piffo, 2020-10-25 01:39:21

Unity animation delay?

There is an object with three animations: rest, run, jump.
The character's legs have a collider that checks whether the character is on the ground or not. If the character is not on the ground, a jump animation is played. Everything works great here.
Rest is always playing when no other animations are playing. This is the main animation. Running is played when the value of the Speed
​​variable becomes greater than 0.01, rest when it is less than 0.01. Script

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
 
public class PlayerAnim : MonoBehaviour
{
    Rigidbody2D rb;
    Animator anim;
 
    public float maxSpeed = 10f;
    bool isGround;
    bool isFacingRight = true;
 
    void Start()
    {
        rb = GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();
    }
 
    void Update()
    {
        anim.SetBool("jump", true);
    }
 
    void FixedUpdate()
    {
        float move = Input.GetAxis("Horizontal");
        anim.SetFloat("Speed", Mathf.Abs(move));
        rb.velocity = new Vector2(move * maxSpeed, rb.velocity.y);
        if (move > 0 && !isFacingRight || move < 0 && isFacingRight)
                Flip();
        anim.SetBool("jump", isGround);
    }
 
    void OnTriggerStay2D(Collider2D col)
    {
        if (col.tag == "ground")
        {
            isGround = true;
        }
    }
 
    void OnTriggerExit2D(Collider2D col)
    {
        if (col.tag == "ground")
        {
            isGround = false;
        }
    }
 
    void Flip()
    {
        isFacingRight = !isFacingRight;
        transform.Rotate(0, 180, 0);
    }
}

I relied on this article .
But there's a problem. The transition from the animation of rest to running and back does not occur immediately, but literally after 1 second. Even when the character is already standing, the running animation plays a little more. With what it can be connected?
5f954af7c02ba230041041.jpeg
5f954b11219a0937383166.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DanielMcRon, 2020-10-25
@piffo

Disable Exit Time in Animation Transitions

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question