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 have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Jumps to high

Discussion in 'Input System' started by pratyushtc, Apr 10, 2022.

  1. pratyushtc

    pratyushtc

    Joined:
    Feb 15, 2021
    Posts:
    6
    Hello, I'm making a 2.5D platformer and I was trying to make my character jump and it does not work, I mean it was working but when I press "space" it jumped way to high.

    Code (CSharp):
    1.  
    2.     public float movementSpeed = 250;
    3.     public float fallMultiplayer = 2.5f;
    4.     public float lowJumpMultiplayer = 2f;
    5.     public float jumpForce = 5;
    6.  
    7.     private Rigidbody rb;
    8.  
    9.     private void Awake()
    10.     {
    11.         rb = GetComponent<Rigidbody>();
    12.     }
    13.  
    14.     void FixedUpdate()
    15.     {
    16.         // Player movement
    17.         float xMovement = Input.GetAxisRaw("Horizontal");
    18.         rb.velocity = new Vector3(xMovement, rb.velocity.y, 0f) * movementSpeed * Time.deltaTime;
    19.         // Player Jump
    20.         if (Input.GetButtonDown("Jump"))
    21.         {
    22.             rb.velocity = Vector3.up * jumpForce * Time.deltaTime;
    23.         }
    24.         if (rb.velocity.y < 0)// improves jump(makes jump similar to mario jump)
    25.         {
    26.             rb.velocity += Vector3.up * Physics.gravity.y * (fallMultiplayer - 1);
    27.         }
    28.         else if (rb.velocity.y > 0 && !Input.GetButton("Jump"))
    29.         {
    30.             rb.velocity += Vector3.up * Physics.gravity.y * (lowJumpMultiplayer - 1);
    31.         }
    32.  
    33.     }
     
  2. pratyushtc

    pratyushtc

    Joined:
    Feb 15, 2021
    Posts:
    6
    The jump now work just that I have to set I've to set it very high like to 100
    Here's a clip of what happens:
     

    Attached Files: