Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We’re making changes to the Unity Runtime Fee pricing policy that we announced on September 12th. Access our latest thread for more information!
    Dismiss Notice
  3. 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.     }