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.
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.
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).
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: