Search Unity

Jump Not The Same on Two Different Scenes

Discussion in 'Physics' started by Jishent, Mar 20, 2019.

  1. Jishent

    Jishent

    Joined:
    Apr 28, 2018
    Posts:
    4
    I imported a movement script from a recent Unity Tutorial in a game that I am currently working on. Everything between the character I am using and the tutorial are the same. Rigidbody has the same values, physics settings has the same values. However, even with these same settings, I can't get the same feel as the character in the example. One different feel while playing the game is that their gravity seems to be heavier? The character falls back to the ground way quicker then in my game. What could be causing the difference? There's no other script that affects the physics or mass.

    Code (CSharp):
    1.         if (input.jumpPressed && !isJumping && (isOnGround || coyoteTime > Time.time))
    2.         {
    3.             //...check to see if crouching AND not blocked. If so...
    4.             if (isCrouching && !isHeadBlocked)
    5.             {
    6.                 //...stand up and apply a crouching jump boost
    7.                 StandUp();
    8.                 rigidBody.AddForce(new Vector2(0f, crouchJumpBoost), ForceMode2D.Impulse);
    9.             }
    10.  
    11.             //...The player is no longer on the groud and is jumping...
    12.             isOnGround = false;
    13.             isJumping = true;
    14.  
    15.             //...record the time the player will stop being able to boost their jump...
    16.             jumpTime = Time.time + jumpHoldDuration;
    17.  
    18.             //...add the jump force to the rigidbody...
    19.             rigidBody.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse);
    20.  
    21.             //...and tell the Audio Manager to play the jump audio
    22.             AudioManager.PlayJumpAudio();
    23.         }
    24.         //Otherwise, if currently within the jump time window...
    25.         else if (isJumping)
    26.         {
    27.             //...and the jump button is held, apply an incremental force to the rigidbody...
    28.             if (input.jumpHeld)
    29.                 rigidBody.AddForce(new Vector2(0f, jumpHoldForce), ForceMode2D.Impulse);
    30.  
    31.             //...and if jump time is past, set isJumping to false
    32.             if (jumpTime <= Time.time)
    33.                 isJumping = false;
    34.         }
    35.  
    36.         //If player is falling to fast, reduce the Y velocity to the max
    37.         if (rigidBody.velocity.y < maxFallSpeed)
    38.             rigidBody.velocity = new Vector2(rigidBody.velocity.x, maxFallSpeed);
    39.     }