- Home /
Skeletal animation executes inconsistently and incorrectly
Hi I've been working on an Infinite Runner to familiarize myself with Unity. I gave the player's character a simple skeletal animation system. I created a 1D blend tree based on vertical speed for jumping and falling. All that works correctly.
However, the player can also perform an air dash while he's jumping. The animation for the air dash never executes correctly. He usually doesn't do the animation at all, instead the air dash executes while holding a pose from the JumpandFall animation. Occasionally the air dash animation occurs, but rather sloppily. He'll dash but his feet will be in the wrong position or it's really jerky.
Here's the part of the code that controls jumping:
void FixedUpdate () { grounded = Physics2D.OverlapCircle(groundCheck.position, groundRadius, whatIsGround); oldYVelocity = rigidbody2D.velocity.y; anim.SetBool("Ground", grounded); if (grounded) { jump = false; airDashAvailable = true; } //float move = Input.GetAxis("Horizontal"); float move = 1f; anim.SetFloat("Speed", Mathf.Abs(move)); anim.SetFloat("vSpeed", rigidbody2D.velocity.y); if (alive && !airDashAvailable && (rigidbody2D.position.x - oldPosition.x) < 6.0f) rigidbody2D.velocity = new Vector2(maxSpeed+8, 0.0f); else if (alive) { if (anim.GetBool("Dashing")) { anim.SetBool("Dashing", false); } rigidbody2D.velocity = new Vector2(move * maxSpeed, rigidbody2D.velocity.y); float xSpeed = (float) move * maxSpeed; rigidbody2D.gravityScale = oldGravityScale; } } void Update () { if (grounded && Input.GetKeyDown(KeyCode.Space) && !jump) { Debug.Log("Initial jump position: " + transform.position.x); anim.SetBool("Ground", false); //rigidbody2D.AddForce(new Vector2(0, jumpForce)); rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, 6.5f); jump = true; } else if (!grounded && Input.GetKeyDown(KeyCode.Space) && airDashAvailable) { airDashAvailable = false; oldPosition = new Vector2(rigidbody2D.position.x, rigidbody2D.position.y); oldGravityScale = rigidbody2D.gravityScale; rigidbody2D.gravityScale = 0.0f; anim.SetBool("Dashing", true); } }
I also included a screenshot of the Animator's state transitions. It plays the Dashing animation when the Dashing variable is set to True. That only occurs if the space bar is pressed while the character isn't on the ground. Any feedback/suggestions would be much appreciated.