Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. On February 28th the Feedback website will shut down and be redirected to the Unity forums. See the full post for more information.
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Unity 2018.3 is now released.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Bad Transition

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

  1. Cobra_2o1o


    Jul 25, 2016
    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;
    6. public class CharacterAnim : MonoBehaviour
    7. {
    8.     Animator animator;
    9.     NavMeshAgent agent;
    11.     void Start()
    12.     {
    13.         animator = GetComponentInChildren<Animator>();
    14.         agent = GetComponent<NavMeshAgent>();
    15.     }
    17.     void Update()
    18.     {
    19.         float speedPercent = agent.velocity.magnitude / agent.speed;
    20.         animator.SetFloat("speedPercent", speedPercent);
    21.     }
    22. }
  2. SilentSin


    Jan 3, 2013
    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.