• 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
Question by johndii1491 · Oct 31, 2014 at 03:50 PM · animationjavascriptjump

How come my player animation won't play?

I have a model and I already have the walk and Idle animation to play but somehow I can never get the "Jump" to play. I really can't figure why?

I used tried triggers but still no good.

here is my code on my model called "AnimatePlayer":

 #pragma strict
 
 var body : Transform; //Tranform the armature of the player model
 
 var mousexThreshold = 0.2; //Number of units for the mouse to move on x-axis
 
 //Settings for the Upper Body rotation
 var sensitivityY = 15F;
 var minimumY = -60F;
 var maximumY = 60F;
 var rotationY = 0F;
 var jumpBool : boolean;
 
 
     function Start()
      {
          //set animation Wrap Mode for the attack to "Once"
          animation["Jump"].wrapMode = WrapMode.Once;
      }
 
 function Update () {
 
 
 if( transform.rotation.eulerAngles.y == 270 ) { // Left rotation
 
 if(Input.GetAxis("Horizontal") > 0) //Walk Backwards
 {
 animation["Walk"].speed = -2;
 animation.Play("Walk");
 }
 
 else if(Input.GetAxis("Horizontal") < 0) //Walk Forward
 {
 animation["Walk"].speed = 2;
 animation.Play("Walk");
 }
 
 else if(Input.GetAxis("Horizontal") == 0)
 {
 animation.Play("Idle");
 }
 }
 
 
 if( transform.rotation.eulerAngles.y == 90.00001 ) { // Right rotation
 
 if(Input.GetAxis("Horizontal") > 0) //Walk Forward
 {
 animation["Walk"].speed = 2;
 animation.Play("Walk");
 }
 
 else if(Input.GetAxis("Horizontal") < 0) //Walk Backwards
 {
 animation["Walk"].speed = -2;
 animation.Play("Walk");
 }
 
 else if(Input.GetAxis("Horizontal") == 0) //Return to standing posture
 {
 animation.Play("Idle");
 }
 }
 
     // Transform the rotation of the player when mouse moves on the x-axis
      var mousex : float = Input.GetAxis ("Mouse X");
      
      if (mousex > mousexThreshold) //Player faces right
      {
    transform.forward = new Vector3(1f, 0f, 0f);
 
      }
      
      
      else if (mousex < -mousexThreshold) //Player faces left
      {
    transform.forward = new Vector3(-1f, 0f, 0f);
 
       }
 
 }
 
 
 function LateUpdate(){
 
     // will make the upper body of the model to be rotatable along the y-axis
 
    rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
             rotationY = Mathf.Clamp (rotationY, minimumY, maximumY);
  
             body.transform.localEulerAngles = new Vector3(0, rotationY, 0); 
           
 }
 
 function OnTriggerEnter(other : Collider){
 if(other.tag == "Ground"){
 animation.Play("Jump");
 }else if(other.tag == "Platform"){
 animation.Play("Jump"); 
 }
 }
 
 function OnTriggerExit(other : Collider){
 if(other.tag == "Ground"){
 animation.Play("Idle");
 }else if(other.tag == "Platform"){
 animation.Play("Idle");
 }
 }

As you can see, I have a trigger to play the "Jump" animation but still nothing. Is it because I have a lot of animations playing all at once?

Comment

People who like this

0 Show 1
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 Tanshaydar · Oct 31, 2014 at 06:59 PM 0
Share

Put a Debug.Log message before jump animation call to see if it ever gets triggered.

1 Reply

· Add your reply
  • Sort: 
avatar image

Answer by JonS · Oct 31, 2014 at 07:53 PM

Looks like two things:

First, I think you have your triggers backwards. You're trying to play the Jump animation when the player lands and playing the Idle animation when he leaves the ground.

Second, you're playing the Walk and Idle animations based on the Horizontal input in Update without any checks to see if he's currently jumping. Even if you play the jump animation properly, Update will immediately play Idle or Walk again the next frame and overwrite the jump.

You need to keep track of when your character is in the air and not call the Horizontal input checks when he is. Ideally you shouldn't be calling animation.Play() constantly in the Update like that. Keep track of what state your character is in, eg Attacking, Jumping, Walking, and only call animation.Play() when he actually changes between states.

Comment

People who like this

0 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 johndii1491 · Nov 01, 2014 at 01:56 AM 0
Share

ohh ok, yeah the trigger I figured out already haha

so I research and found another animation command called "animation.CrossFade()".

and my other question is, when you mean by checks do you mean "boolean"?

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

How do I get my "dashing" animation to work? 1 Answer

Making a character jump with the Character Controller Component instead of Capsule Collider 0 Answers

2D Animation with JavaScript (Android). Help! 0 Answers

How do I get my jump animation to work? 1 Answer

If an specifc animation is playing dont let other animations play. 1 Answer


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