Search Unity

  1. Unity 2019.1 is now released.
    Dismiss Notice

Bad Transition

Discussion in 'Animation' started by Cobra_2o1o, Feb 10, 2019.

  1. Cobra_2o1o

    Cobra_2o1o

    Joined:
    Jul 25, 2016
    Posts:
    13
    I've made recording showing the problem. The idle is working well but when I start moving, the walk animation is glitching out.



    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5.  
    6. public class CharacterAnim : MonoBehaviour
    7. {
    8.     Animator animator;
    9.     NavMeshAgent agent;
    10.  
    11.     void Start()
    12.     {
    13.         animator = GetComponentInChildren<Animator>();
    14.         agent = GetComponent<NavMeshAgent>();
    15.     }
    16.  
    17.     void Update()
    18.     {
    19.         float speedPercent = agent.velocity.magnitude / agent.speed;
    20.         animator.SetFloat("speedPercent", speedPercent);
    21.     }
    22. }
    23.  
     
  2. SilentSin

    SilentSin

    Joined:
    Jan 3, 2013
    Posts:
    264
    I'm not sure what the problem is, but even if you got this approach working properly it would still be much better to use a blend tree for this. Just a simple 1D blend tree containing the two animations and using the speed parameter to blend between them.