Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Question animator.setfloat damptime loops in Blend Tree

Discussion in 'Scripting' started by Caliber, Oct 4, 2020.

  1. Caliber

    Caliber

    Joined:
    Feb 11, 2018
    Posts:
    85
    I have following code running in Update on an object that is controlled by NavMesh:
    Code (CSharp):
    1. float movementSpeed = 0f;
    2.         movementSpeed = navMeshAgent.isStopped ? 0f : navMeshAgent.velocity.magnitude;
    3.         animator.SetFloat("TestNavMeshSpeed", navMeshAgent.velocity.magnitude);
    4.  
    5.         animator.SetFloat("MovementSpeed", movementSpeed, 0.5f, Time.deltaTime);
    6.        Debug.Log("TestNavMeshSpeed: " + movementSpeed.ToString()); // Output confirms that movementSpeed does in fact stay 0
    TestNavMeshSpeed is only used for debugging.
    Initially, everything works fine, see first 3 screenshots in attached image.
    animatorFloatDamp.png

    As TestNavMeshSpeed jumps from 6.0 (not pictured) to 1.9 to 0, MovementSpeed is reduced smoothly to 0. In the Animator parameters list, MovementSpeed stays correctly at 0 after TestNavMeshSpeed has been 0 for a while.
    The weird thing is that after reaching 0, MovementSpeed jumps up to ~10 (see bottom screenshot, 9.84748) in the Blend Tree only, damps down 0, and continues looping.

    I was under the assumption that the MovementSpeed parameter in the animator and in the Blend Tree would always be in sync. Am I doing something wrong, or is this a bug?

    Note: the damping takes a bit longer than 0.5 sec. First it ramps down quickly, as expected, but after reaching approximately MovementSpeed 0.5, it takes several seconds for it to reach 0.00001 (or something very low), before it loops over. Not sure if this is connected.
     
  2. Wranbell

    Wranbell

    Joined:
    Jun 27, 2022
    Posts:
    1
    I have the same problem. Did you find a solution?