Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Jump animation bool randomly going to false while jumping

Discussion in 'Animation' started by jungle_, Mar 15, 2021.

  1. jungle_

    jungle_

    Joined:
    Sep 13, 2020
    Posts:
    17
    Hi All,

    I am trying to implement jumping into my simple 2D platformer. The way I am handling the animations is that I'm checking if the player is colliding with the ground. If so, I set my isJumping parameter to false. If he's not colliding with the ground, I set it to true.

    I am running into an issue where about 50% of the time that I jump, my isJumping parameter is setting to true, then immediately back to false. I have messed around with implementations for ~3 hours and can't seem to figure out why or a way around this issue.

    See attached picture for Unity info.

    Below is the relevant code snippet for checking for grounding and setting the animation parameter. The jumpPressedRemember and that stuff is to handle coyote time.

    Code (CSharp):
    1. void Update() {
    2.         bool bGrounded = Physics2D.OverlapCircle(m_GroundCheck.position, k_GroundedRadius, m_WhatIsGround);
    3.  
    4.         fGroundedRemember -= Time.deltaTime;
    5.         if (bGrounded) {
    6.             fGroundedRemember = fGroundedRememberTime;
    7.             animator.SetBool("isJumping", false);
    8.         }
    9.  
    10.         fJumpPressedRemember -= Time.deltaTime;
    11.         if (Input.GetButtonDown("Jump")) {
    12.             fJumpPressedRemember = fJumpPressedRememberTime;
    13.         }
    14.  
    15.         if (Input.GetButtonUp("Jump")) {
    16.             if (myRB.velocity.y > 0) {
    17.                 myRB.velocity = new Vector2(myRB.velocity.x, myRB.velocity.y * fCutJumpHeight);
    18.             }
    19.         }
    20.  
    21.  
    22.         if ((fJumpPressedRemember > 0) && (fGroundedRemember > 0)) {
    23.             fJumpPressedRemember = 0;
    24.             fGroundedRemember = 0;
    25.             animator.SetBool("isJumping", true);
    26.             myRB.velocity = new Vector2(myRB.velocity.x, fJumpVelocity);
    27.         }
     

    Attached Files:

    • jump.png
      jump.png
      File size:
      321.1 KB
      Views:
      10
unityunity