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 ?