Hi, I’m learning how to use the package Input System, I have this code.
The problem is, when I press one of the Jump bindings (I have the bindings with an action map), usually It doesn’t work, with rb.AddForce
, if I do it with transform.Translate()
the player jumps without problems. The gravity of the project is in -9.81
, the gravity scale of my player is in 50
, and his mass is in 1
. I’ll add a video with the problem, every time the consoles says "Jump"
one of the Jump bindings was pressed.
I wrote this on reddit, I put the video there, here’s the link of the post Reddit - Dive into anything
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class MovimientoJugador : MonoBehaviour
{
#region variables
public PlayerInput playerInput;
private Rigidbody2D rb;
private PlayerControls myinput;
public float velocidad = 10f;
public float salto = 10f;
private Vector2 movimiento;
private float movimientox;
#endregion
void Start()
{
rb= GetComponent<Rigidbody2D>();
playerInput= GetComponent<PlayerInput>();
myinput = new PlayerControls();
myinput.Exploracion.Enable();
}
void Update()
{
ProcesarMove();
ProcesarJump();
}
private void ProcesarMove()
{
#region Valores de movimiento
movimiento = myinput.Exploracion.Move.ReadValue<Vector2>();
movimientox = movimiento.x;
#endregion
#region Movimiento Horizontal
rb.velocity = new Vector2(movimientox * velocidad, 0f);
#endregion
}
private void ProcesarJump()
{
#region Salto
if (myinput.Exploracion.Jump.WasPressedThisFrame())
{
Debug.Log("Jump");
rb.AddForce(Vector2.up + new Vector2(0f, salto), ForceMode2D.Impulse);
}
#endregion
}
}
If you didn’t understand which is the problem who I have let me know and I´ll try explain it better, it’s a bit difficult to me because my english isn’t very good.