• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by PurpleComet · Nov 25, 2015 at 08:48 PM · animation2d-platformeranimationstate

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); } }

alt text 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.

screen-shot-2015-11-24-at-123534-pm.png (36.4 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Accessing AnimationState in Animator 0 Answers

Make Animation Loop X Times C# 2 Answers

A problem regarding to player animation with checkpoint in 2D platformer 0 Answers

I am attempting to play an animation in reverse and slow it down, But it only seems to play forwards. 2 Answers

2d character stuck in jump 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges