Gamepad is making the player Jump Higher

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerMovement : MonoBehaviour
{
    public Rigidbody2D rb;

    public float MoveSpeed;

    public float JumpHieght;

    private Vector2 MoveDirection;

    public InputActionReference jump;

    public InputActionReference Move;
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
        MoveDirection = Move.action.ReadValue<Vector2>();

        rb.velocity = new Vector2(x: MoveDirection.x * MoveSpeed, y: transform.position.y);
    }

    private void OnEnable()
    {
        jump.action.started += Jump;
    }
    private void OnDisable()
    {
        jump.action.started -= Jump;
    }

    private void Jump (InputAction.CallbackContext obj)
    {
        transform.position = new Vector2(transform.position.x, transform.position.y + JumpHieght);
    }
}

I am using the input system to make a jump you can either tap space on keyboard or west button and north button on gamepad. When I tap space I jump the value of JumpHieght like intended but when I jump via the gamepad I jump around 2-3 times higher than the JumpHieght.

What can I do to make the JumpHieght consistent across Keyboard and Gamepad ?

Likely because the callback is happening more than you expect.

You can easily debug this with a Debug.Log call:

private void Jump (InputAction.CallbackContext obj)
{
    Debug.Log("Jump pressed!")
    transform.position = new Vector2(transform.position.x, transform.position.y + JumpHieght);
}

I think you want to subscribe to InputAction.performed rather than .started.

That said, your jump is completely bypassing physics, so you should change it to use physics.

Thanks how do i implement this ?