Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Jump is snappy when using rigidbody.AddForce(Vector3.Up, ForceMode.Impulse)

Discussion in 'Physics' started by FfelipeHernandez, Apr 15, 2023.

  1. FfelipeHernandez

    FfelipeHernandez

    Joined:
    Dec 3, 2020
    Posts:
    2
    Hello! I'm making a skating game and with my skate controller I want the player to hold the jump to determine how much height they get from the jump, but when I add the force when the player stops hitting the space bar, the player gets height perfectly, but it almost teleports instead of making a jump.

    This is the code, I just made a simple jump with RigidBody.AddForce(Vector3.Up * force, ForceMode.Impulse):

    Code (CSharp):
    1. public void Jump()
    2.     {
    3.         if (Input.GetButton("Jump"))
    4.         {
    5.             if (skateJumpPreassure < maxSkateJumpFoce) { skateJumpPreassure += Time.deltaTime * skateJumpMultiplier; }
    6.             else { skateJumpPreassure = maxSkateJumpFoce; }
    7.         }
    8.         if (Input.GetButtonUp("Jump"))
    9.         {
    10.             skateJumpPreassure += skateJumpPreassure + minSkateJumpFoce;
    11.             rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z);
    12.             newmanager2.PlaySound("Skate Jump");
    13.  
    14.             rb.AddForce(Vector3.up * skateJumpPreassure, ForceMode.Impulse);
    15.             skateJumpPreassure = 0;
    16.         }
    17.     }