Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

animator.SetFloat transitioning too fast... (Blend Tree)

Discussion in 'Animation' started by Rio_TFF, Aug 13, 2020.

  1. Rio_TFF

    Rio_TFF

    Joined:
    Aug 4, 2019
    Posts:
    21
    Heyo,

    In Play mode, the Grounded Blend parameter is transitioning from "0" to "9" instantly instead of smoothing between the two floats...



    I'm using the following script:

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CharacterAnim : MonoBehaviour
    6. {
    7.  
    8.  
    9.     public GameObject player;
    10.     private Animator anim;
    11.  
    12.     // Start is called before the first frame update
    13.     void Start()
    14.     {
    15.         anim = GetComponent<Animator>();
    16.     }
    17.  
    18.     // Update is called once per frame
    19.     void Update()
    20.     {
    21.         if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
    22.         {
    23.             anim.SetFloat("Grounded Blend", 9f);
    24.         }
    25.  
    26.         else
    27.         {
    28.             anim.SetFloat("Grounded Blend", 0f);
    29.         }
    30.     }
    31.  
    32.     void FixedUpdate()
    33.         {
    34.          
    35.         }
    36. }
    Any thoughts or ideas would be greatly appreciated...

    This is Unity 2019.4.8f1
     
    Last edited: Aug 13, 2020
  2. Rio_TFF

    Rio_TFF

    Joined:
    Aug 4, 2019
    Posts:
    21
    For anyone curious, I ended up fixing this by adding this structure to my script:

    public void SetFloat(string name, float value, float dampTime, float deltaTime);

    So now it looks like this:

    Code (CSharp):
    1. void Update()
    2.     {
    3.         if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
    4.         {
    5.                         //(string name, float value, float dampTime, deltaTime)
    6.             anim.SetFloat("Grounded Blend", .1f, .1f, Time.deltaTime);
    7.         }
    8.  
    9.         else
    10.         {
    11.             anim.SetFloat("Grounded Blend", 0f, .1f, Time.deltaTime);
    12.         }
    13.     }
     
    xavi-farre likes this.