1
\$\begingroup\$

re-imported my character today with 3 new animations (JumpStartState, JumpDownState, JumpEndState) and moved all animation code into the PlayerController script. All of my animations are handled by transitions and their parameters in the Animator. The controls are very responsive but I can't get the transitions to end immediately before before an animation plays out.

enter image description here

I can make the character jump instantly after hitting the ground from a previous jump (a la Mario 64), but his animation is delayed until the landing animation finishes. This is the most notable example of animation not being responsive.

enter image description here

I have read through forums going back to 2011 trying to find a solution to this problem and everyone says either "un-check 'Has-Exit-Time'," "set 'Exit Time' to zero," or "move the blue bars close together (same thing, by the way)". None of that has worked for me. Most of the time there was no difference at all; Other times my character would just skate frozen through the scene like a cardboard Frosty (animation stalls on start).

enter image description here enter image description here

I have a link to a NEW short demo where I bounce my player around the room while the animation graph is giving live feedback here (01:50):

Character Animation Graph Live with Preview

EDIT: Looking at the footage, maybe there is an animation "kink" between the "JumpDownState" and "JumpEndState" that is happening at least half the time but even when it doesn't, the animation must play through for the next to start.

I am attaching my code just in case:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{

    private float charSpeed;
    public float walkSpeed;
    private float runSpeed;
    public float jumpForce;
    private float coyoteTime = 0;
    private const float MAXCOYOTETIME = 0.1f;
    private float currentHeight;
    private float previousHeight;
    private float travel;
    public CharacterController controller;
    private Animator animator;
    public float gravityScale;
    private Rigidbody rb;

    public static Vector3 moveDirection;

    // Start is called before the first frame update
    void Start()
    {
        controller = GetComponent<CharacterController>();
        rb = GetComponent<Rigidbody>();
        animator = GetComponent<Animator>();
        charSpeed = walkSpeed;
        runSpeed = walkSpeed * 2;
        previousHeight = currentHeight;
    }

    // Update is called once per frame
    void Update()
    {

        currentHeight = transform.position.y;
        travel = currentHeight - previousHeight;
        if (Input.GetButton("Fire3"))
        {
            charSpeed = runSpeed;
            animator.SetBool("isRunning", true);
        }
        else
        {
            charSpeed = walkSpeed;
            animator.SetBool("isRunning", false);
        }

        // Declare movement vector
        moveDirection = new Vector3(Input.GetAxis("Horizontal") * charSpeed,
            moveDirection.y,
            Input.GetAxis("Vertical") * charSpeed);

        // Set y-axis movement conditions (jumping, grounded, free-fall)
        #region jumping
        if (IsGrounded() && Input.GetButton("Jump"))
        {
            animator.SetBool("isJumping", true);
            moveDirection.y = jumpForce;

        }

        else if (IsGrounded() == false)
        {
            moveDirection.y = moveDirection.y + Physics.gravity.y * gravityScale * Time.deltaTime;
            if (moveDirection.y < 0)
            {
                animator.SetBool("isJumping", false);
                animator.SetBool("isFalling", true);
                if (travel == 0 && Input.GetButton("Jump"))
                {
                    animator.SetBool("isJumping", true);
                    animator.SetBool("isFalling", false);
                }
            }
        }
        #endregion
        if (travel == 0)
        {
            animator.SetBool("isFalling", false);
            animator.SetBool("isJumping", false);
        }

        // rotated 45 deg to align controls to camera instead of world space:
        Vector3 rotated = Quaternion.Euler(0, -45, 0) * moveDirection;
        controller.Move(rotated * Time.deltaTime);

        if (Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0)
        {
            animator.SetBool("isMoving", false);
        }
        else
        {
            animator.SetBool("isMoving", true);
        }

        Vector3 lookDir = new Vector3(rotated.x, 0, rotated.z);

        if (lookDir != Vector3.zero)
        {
            transform.rotation = Quaternion.LookRotation(lookDir);
        }

        previousHeight = currentHeight;
    }

    public bool IsGrounded()
    {
        return coyoteTime < MAXCOYOTETIME;
    }

    void LateUpdate()
    {
        if (controller.isGrounded)
        {
            coyoteTime = 0;
        }
        else
        {
            coyoteTime += Time.deltaTime;
        }
    }
}

EDIT: IRONING OUT THE LAST WRINKLE! NEW DEMO!(6:30 or less)

Excited to say that all animations proceed immediately now except that repeated jump. Still, half the time the transition to a new jump doesn't happen at all. New footage of improved movement though, plus further description of problem:

Snappier Locomotion; Ironing out the last wrinkle!

\$\endgroup\$
10
  • \$\begingroup\$ Included parameter values for all jump transitions \$\endgroup\$ Commented Jul 17, 2019 at 6:32
  • \$\begingroup\$ All of your screenshots show "Has Exit Time" checked. That forces the animation to wait until the exit time before transitioning to a new animation. Your transition blends look unusually long too. \$\endgroup\$
    – DMGregory
    Commented Jul 17, 2019 at 11:59
  • \$\begingroup\$ Yeah, I tried a lot of things that weren't working as expected until eventually I left most transitions at default values to be safe. Oh, and I see that I forgot to click the drop-down arrow. Otherwise you would see that almost all of my transition fields are 0. I was able to turn everything off/0 last night without my character blowing up, big improvement. I have instant transitions now on everything except repeated jumps, which is the last thing to figure out here. Do you think it has something to do with how I am checking for groundedness? \$\endgroup\$ Commented Jul 17, 2019 at 17:35
  • \$\begingroup\$ Looks like you're not advancing your coyote time when you jump. \$\endgroup\$
    – DMGregory
    Commented Jul 17, 2019 at 17:39
  • \$\begingroup\$ Really? The LateUpdate() method is supposed to ONLY advance coyoteTime when the character is not grounded (that is, falling or jumping, according to Else condition). Are you saying that LateUpdate() doesn't run when I jump? I thought it ran asynchronously with Update()? Is it because I have to run through Update before LateUpdate() runs? Please clarify \$\endgroup\$ Commented Jul 17, 2019 at 20:23

1 Answer 1

2
\$\begingroup\$

From Screen shot its look like the animation transition has some value to "Transition duration(%)" and also I guess "Fixed duration" is checked.

So My suggestion is to set "Transition duration(%)" to 0 also uncheck the "Fixed duration" and "Has Exit" Check boxes as shown in the screen shot. I hope it works, Cheers!

enter image description here

\$\endgroup\$
4
  • \$\begingroup\$ I made sure everything is set as you described and there is a MASSIVE improvement to all animations, which are very snappy now...except repeated jumps. This must be a programming thing? Maybe how I'm checking for groundedness? The program knows the user is pressing the jump button but there is still a huge delay in the animation. You helped a lot but please let me know tomorrow if you dream of anything else =j \$\endgroup\$ Commented Jul 17, 2019 at 7:12
  • \$\begingroup\$ I am glad it helped. I will check the details you posted with extra concentration later as right now i am in office... So.... \$\endgroup\$
    – Swati
    Commented Jul 17, 2019 at 7:24
  • \$\begingroup\$ Yeah, take your time. I am going to bed. I will upload a new video to show his new springy-ness. I also doubled the gravity scale and increased the jumpForce by 2. This is looking really solid, If I can just get a dependable jump animation, I'm in business! :D \$\endgroup\$ Commented Jul 17, 2019 at 7:26
  • \$\begingroup\$ For the people reading this just now like me: You need set "Can Transition To Self" to false es well. Otherwise it restarts the animation instantly and you see a still image. \$\endgroup\$
    – Antitheos
    Commented May 1, 2023 at 11:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .