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
4
Question by Trevor_trev · Jan 31, 2020 at 10:31 AM · animation2d-platformerjumpingwontwork

Jump animation only plays for about 1/10 of a second unless the button is pressed twice

I just started learning how to use Unity. I'm working on a 2D platformer using tutorial videos from the youtube channel "Brackeys". My method is to go through one video, following his instructions to a T, and repeating that same video through multiple iterations before moving on to the next video. For a reason that i cant figure out, one of my iterations wont properly play the jumping animation.

In the animation preview window it looks perfectly fine, but when doing a test run the animation will only play for a split second before reverting back to the animation before it (either run or idle). Although it will play all the way through if I press the button twice. When looking at the parameters tab in the animation window, I can see the "IsJumping" parameter is activated for that split second when i press the jump button but then it unchecks immediately after. The weirdest part is that I've checked about five times and as far as I can see everything is exactly the same between the iteration that doesnt work and the one that does. Any help or advice would be greatly appreciated!

Here is the movement script:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Playermovement : MonoBehaviour {
 
     public CharacterController2D controller;
     public Animator animator;
 
     public float runSpeed = 40f;
 
     float horizontalMove = 0f;
     bool jump = false;
     bool crouch = false;
 
     // Update is called once per frame
     void Update() {
 
         horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;
 
         animator.SetFloat("Speed", Mathf.Abs(horizontalMove));
         
         if (Input.GetButtonDown("Jump"))
         {
             jump = true;
             animator.SetBool("IsJumping", true);
         }
 
         if (Input.GetButtonDown("Crouch"))
     {
            crouch = true;
     } else if (Input.GetButtonUp("Crouch"))
     {
         crouch = false;
     }
 
      }
 
     public void OnLanding()
     {
         animator.SetBool("IsJumping", false);
     }
 
    public void OnCrouching (bool isCrouching)
    {
        animator.SetBool("IsCrouching", isCrouching);
    }
     void FixedUpdate ()
    {
        // Move our character
        controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
        jump = false;
       }
 }
 
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

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by casemer · Feb 09, 2020 at 03:29 AM

@Trevor_trev I figured it out! My issue was not in the PlayerMovement, it is in the CharacterController. In the FixedUpdate, there is this part:

             m_Grounded = true;
             if (!wasGrounded)
                 OnLandEvent.Invoke();
         }

get rid of that "!" I am not sure why his code had it but it should not be there.

             m_Grounded = true;
             if (wasGrounded)
                 OnLandEvent.Invoke();
         }

Hope this was the same issue for you and this fixes it!

Comment
Add comment · Show 10 · 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 Trevor_trev · Apr 03, 2020 at 08:46 PM 0
Share

Awesome! Thanks! I thought this question was too buried for anyone to answer so I didn't check back until now haha.

avatar image teruyakimura · Apr 09, 2020 at 06:35 PM 0
Share

I was looking at the same code and tried to remove the '!' character. However, the bug remains the same...

avatar image Lonlitay teruyakimura · Apr 20, 2020 at 08:51 AM 0
Share

$$anonymous$$e too... @teruyakimura did you find the solution??

avatar image teruyakimura Lonlitay · Apr 23, 2020 at 09:22 PM 0
Share

Yes! Actually, I seached the issue in the YT commentary section, and what worked for me was change the variable value k_GroundedRadius to .05f. It is located in the Controller2D.

Show more comments
avatar image MrBunBuns6969 · Dec 14, 2020 at 07:17 PM 0
Share

I am experiencing the same problem as you, and also following Bracky's tutorial. I cant find the code that says:

     m_Grounded = true;
                  if (!wasGrounded)
                      OnLandEvent.Invoke();
              }

Where is it? Thank you!

avatar image NcNtt · Feb 19, 2021 at 08:46 PM 0
Share

Hi, i know it been over a year, but now its my time and i found this... and i found out that just deleting the "!" from !wasGrounded does nothing else than repeating the OnLandEvent... i found this out by adding a sound to the landing animation and was wondering why i hear this ticking all the time... it was the ever repeating sound of the landing animation.... Which now fires all the time and every frame again, that you dont see the animation but hear the beginning of the sound.

Well, i found this thread because my character startedt (right today with no warning) to DONT show the jump animation anymore... instead he was just standing and jumping up in idle... with the second hit of the spacebar i could see the animation....

If anyone has found out whats going on here please let me know!

But know: Its not just deleting an ! and its all good - thats the bad way :) thanks guys!

avatar image
0

Answer by NcNtt · Feb 19, 2021 at 09:02 PM

And here i am again - with an answer - in the CharacterController2D Script, that all of you, who rebuilt the Brackeys stuff, should have - there is a section called:

 // If the player should jump...
         if (m_Grounded && jump)
         {
             // Add a vertical force to the player.
             m_Grounded = false;
             m_Rigidbody2D.AddForce(new Vector2(0f, m_JumpForce));
         }

Please correct the false to true... Reason: The script checks constantly if the Player isGrounded - which you have to set by giving the component a material or a collider and set this to "WhatIsGround" - you should have this in the Inspector window under your CharacterController2D script as a float.

Now, the script asks the following:

If the Player is grounded and enters jump state please AddForce to the Rigidbody called JumpForce. (also to be set in the inspector.

Now the script also says, which is funny - m_Grounded=false; which doesnt make any sense at all. So in my case it only showed the jump anymation when im in midair, so to say NOT GROUNDED - which was correct in terms of the script.

So please set it to

 m_Grounded = true;

and the problem should be corrected.

This is my state of knowledge and i think there are many others out there knowing better - but hey - i wrote this! you not! ^^

Have fun!

Comment
Add comment · 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

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

316 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 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 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 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 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 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 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 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 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 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 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

Choose Start and End Frame for 2D Animation 0 Answers

Even / Constant Speed and Jumping 2D 1 Answer

3DBuzz Third Person Character Jumping And Landing Issue 0 Answers

Animation Parameters Not Working Correctly 0 Answers

Animation of the death (2D Game) 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