Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 georgeq · Sep 15, 2015 at 10:56 PM · androidanimatormecanim

Animation not playing all the times on Android.

When I play my game on the editor or when I build the PC version, all the animations play at the right time, however on Android, the Jump animation is not always played. Basically I have two bool parameters: "Running" and "Jump", when Running is set to false and Jump is set to true, the Jump animation is played, upon collision with the ground Running is set to true and Jump is set to false, because under these conditions the Run animation is played.

The original code was like this:

 public void Jump(){
      Body.velocity = new Vector2(0,0);
      Body.AddForce(new Vector2(0,360));
      Anim.SetBool("Running",false);
      Anim.SetBool("Jump",true);
      Jumping = true;
 }


 void OnCollisionEnter2D(Collision2D co){
      if(Jumping){
         Jumping = false;
         Anim.SetBool("Jump",false);
         Anim.SetBool("Running",true);
      }
 }


But while testing in the editor, I realized sometimes (about 1 out of each 100 times) the Jump animation didn't play, it was hard to track what happened inside the Animator Controller, but with the aid of the editor tools I found out that some times, for some unknown reason the "Jump" parameter remained true after collision with the ground... So I modified the Jump function like this:

 public void Jump(){
     if(Anim.GetBool("Jump")){
         Anim.SetBool("Jump",false);
         Anim.Play("PlayerRun",-1,0);
         return;
      }
      Body.velocity = new Vector2(0,0);
      Body.AddForce(new Vector2(0,360));
      Anim.SetBool("Running",false);
      Anim.SetBool("Jump",true);
      Jumping = true;
 }

I also added some debug code and ran extensive tests in order to find out if these changes really solved the problem, and they did. I've been running the game for several days and the problem hasn't showed up again in both the editor and the PC build... however when I run the game in Android the character does jump, but the Jump animation not always plays, about 1 out of every 20 or 30 times the animation simply doesn't play. In order to see what was happening with the parameters, I added some debug code, but only to confirm that when the problem pops up, both parameters have the right values... so I don't know what's going on.

I can't tell if this is a Unity's bug but if it isn't, then what am I doing wrong?

by the way, I'm working with Unity 5.1.3

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Kakaku · Sep 16, 2015 at 03:37 PM

OnCollisionEnter2D it means you are working in 2d mode let me Ask few question to understand it properly

  1. did you just upgrade your unity to unity 5.1.3 from lower version? or you just start with fresh Unity 5.1.3 Installment?

  2. for jump instead of

    Body.Velocity = new Vector2(0,0);

    Body.AddForce(new Vector2(0,360));

    Try to use

var jupSpeed:float = 15.0;

rigidbody2D.velocity.y = jupSpeed;

onGround = false;

function OnCollisionEnter2D(down :Collision2D)

{ onGround = true; }

Comment
Add comment · Show 1 · Share
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
avatar image georgeq · Sep 16, 2015 at 04:28 PM 0
Share

I upgraded from version 5.1.2... the physics and the collisions work all right, there's no problem with that at all. I'm using OnCollisionEnter2D to trigger the run animation and that works just fine. So, the jump process itself works just fine, the problem is in the animator, the jump animation doesn't play all the times... it does play, but not always... so there are times in which, when the character jumps it keeps moving as if it was walking on solid ground... but it is on middle air! so the jump doesn't look realistic... that's all the problem. It is an animation problem! not a physics problem nor a collision problem. Like I said this is an Android exclusive problem.

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.

Follow this Question

Answers Answers and Comments

30 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Error getting animation info with Animator 0 Answers

How to superimpose two animations using the animator? 0 Answers

Is it possible to play animator transition in script? 1 Answer

Animation Curves and Mecanim 0 Answers

Getting error clipCount == internalClipCount 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