My jumping system doesn't work

In my jump system is something wrong, when i am clicking space button most of the times nothing happens butsomatimes it just teleport me up a bit .I was trying to do a smooth jump or just a simple jump that i can use every time i want .Do not help me in something like “Is Grounded”.Only thing i want is jump .Dow bellow is my code:

(ignore dashing and moving system, if you want to help me focus on a jumping system)

using System.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;

public class Player : MonoBehaviour
{
    private Rigidbody2D rb;
    public int movingSpeedX;
    private float speedX;
    public int jumpForce;
    private bool canDash = true;
    private bool isDashing = false;
    public float DashingPower = 20;
    public float dashingTime = 0.3f;
    public float DashingCooldown = 1f;
    public float gravityDeecreser = 2f;
    private int keyCounterA = 0;
    private int keyCounterD = 0;
    [SerializeField] private TrailRenderer tr;
    private void Start()
    {
        rb = GetComponent<Rigidbody2D>();  
    }
    private void Update()
    {
        if (keyCounterD > 2)
        {
            keyCounterD = 0;
        }
        else if (keyCounterD > 0)
        {
            Invoke(nameof(KeyReseterD), 0.3f);
        }
        if (keyCounterA > 2)
        {
            keyCounterA = 0;
        }
        else if (keyCounterA > 0) {
            Invoke(nameof(KeyReseterA), 0.3f);
        }


        if (isDashing == true)
        {
            return;
        }



        speedX = Input.GetAxis("Horizontal") * movingSpeedX;
        rb.velocity = new Vector2(speedX, 0);



        if (Input.GetKeyDown(KeyCode.Space))
        {
            rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
        }




        if (Input.GetKeyDown(KeyCode.A))
        {
            if (keyCounterA == 1&&canDash==true)
            {
                
                StartCoroutine(DashLeft());
                keyCounterA = 0;
            }
            else
            {
                keyCounterA += 1;
            }                     
        }
        if (Input.GetKeyDown(KeyCode.D))
        {
            if ( keyCounterD == 1 && canDash == true)
            {                
                StartCoroutine(DashRight());
                keyCounterD = 0;
            }
            else
            {
                keyCounterD += 1;
            }           
        }
    }
    
    private IEnumerator DashRight() {
        canDash = false;
        isDashing = true;
        float OrginalGravity = rb.gravityScale;
        rb.gravityScale = gravityDeecreser;
        rb.velocity = new Vector2(transform.localScale.x * DashingPower, 0f);
        tr.emitting = true;
        yield return new WaitForSeconds(dashingTime);
        tr.emitting = false;
        rb.gravityScale = OrginalGravity;
        isDashing = false;
        yield return new WaitForSeconds(DashingCooldown);
        canDash = true;

        }
    private IEnumerator DashLeft()
    {
        canDash = false;
        isDashing = true;
        float OrginalGravity = rb.gravityScale;
        rb.gravityScale = gravityDeecreser;
        rb.velocity = new Vector2(transform.localScale.x * -DashingPower, 0f);
        tr.emitting = true;
        yield return new WaitForSeconds(dashingTime);
        tr.emitting = false;
        rb.gravityScale = OrginalGravity;
        isDashing = false;
        yield return new WaitForSeconds(DashingCooldown);
        canDash = true;
    }
    private void KeyReseterD() {
        keyCounterD = 0;
    }
    private void KeyReseterA()
    {
        keyCounterA = 0;
    }
}

“Doesn’t work” isn’t a useful description.

How to report your problem productively in the Unity3D forums:

http://plbm.com/?p=220

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you are missing any information above, we certainly don’t have it!

This only means it time for you to start debugging!

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Your code works perfectly fine in my game.

private void Jump()
{
if (Input.GetKeyDown(KeyCode.Space) && isTouchingGround)
{
//m_rb.velocity = new Vector2(m_rb.velocity.x, jumpSpeed);
m_rb.AddForce(Vector2.up * jumpSpeed, ForceMode2D.Impulse);
jetSmoke.Play();
}
if(!isTouchingLadder)m_animator.SetBool(ac_jump, isTouchingGround);
}

you should add some debuger to see if something in your code is stopping your jump.