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

Blend tree animated character slides before animation starts

Discussion in 'Animation' started by Raidenwins, Sep 14, 2018.

  1. Raidenwins

    Raidenwins

    Joined:
    Dec 18, 2012
    Posts:
    109
    I have an animation blend tree with two sub-trees, both with blend type of 1D, one for walking and one for running.

    upload_2018-9-13_20-13-31.png

    upload_2018-9-13_20-32-0.png

    All animations are imported from Mixamo. The problem I am having is that when I start the game and I press the Up arrow key, to make the character run, he slides for about two seconds before he starts running. Here is a short YouTube video illustrating the problem:



    The code for detecting player inputs and triggering animations looks like this:

    Code (CSharp):
    1. [RequireComponent(typeof(CharacterController))]
    2. public class MyController
    3. {
    4.     private CharacterController _controller;
    5.     private IMovementInputHandler _movementInputHandler;
    6.     private Transform cameraTransform;
    7.  
    8.     void Awake()
    9.     {
    10.          _controller = GetComponent<CharacterController>();
    11.     }
    12.  
    13.     void Start ()
    14.     {
    15.         _animator = GetComponent<Animator> ();
    16.     }
    17.  
    18.     void FixedUpdate ()
    19.     {
    20.         float horizontalInput = _movementInputHandler.HorizontalInput();
    21.         float verticalInput = _movementInputHandler.VerticalInput();
    22.  
    23.         cameraTransform = Camera.main.transform;
    24.      
    25.         DebugConsole.Log ("Horizontal input is: " + horizontalInput + ", Vertical is: " + verticalInput);
    26.  
    27.         _animator.SetFloat ("Speed", verticalInput);
    28.         _animator.SetFloat ("Direction", horizontalInput);
    29.  
    30.         Move (horizontalInput, verticalInput, cameraTransform);
    31.  
    32.         // Calculate movement
    33.         Vector3 movement = _moveDirection * _moveSpeed + new Vector3 (0, _verticalSpeed, 0);
    34.      
    35.         // Move
    36.         _controller.SimpleMove (movement);
    37.     }
    38. }
    If I select my main blend tree, in the Animator window, and set the Speed parameter to 1, the character immediately starts running, but when I run the game, the sliding starts happening.

    What is the problem here?
     
    Last edited: Sep 16, 2018
  2. Raidenwins

    Raidenwins

    Joined:
    Dec 18, 2012
    Posts:
    109
    Sorry for the shameless bump, but I am really stuck on this. Any ideas on what could be causing the problem above?
     
  3. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    3,610
    "This video is unavailable"

    Did you set it to private?
     
  4. Raidenwins

    Raidenwins

    Joined:
    Dec 18, 2012
    Posts:
    109
    Oh my bad. Yes, it was private. I set it to unlisted so you should be able to see it now. However, I've resolved the problem already. It wasn't caused by anything to do with blend trees. The problem was the "Has Exit Time" checkbox in the Inspector window for a transition between the Idle state and the blend tree (see screenshot below). I figured it out when my walking animation started doing the sliding thing too, even though it had been working fine all along and it wasn't even in a blend tree.

    My guess is, when I created a transition between my Idle state and the blend tree in question, the "Has Exit Time" checkbox was checked by default. Once I unchecked it, the sliding disappeared and my animations started working correctly:

    upload_2018-9-17_19-23-42.png
     
    conradi likes this.