The problem is that my character sometimes jumps high and after 5/6 button press he jumps really low.
the only thing i did different from Rick is that i used to put the input detection in the Update method and the physics management in FixedUpdate.
if i try to call the Jump in Update the issue does not occur, but in these days i believed i understood that common sense was to listen for Input only in Update, and for physics related stuff (rigidbody, forces etc…) in FixedUpdate why does this happen
bool checkjump;
float dir;
float controlThrow;
private void Update()
{
InputDetection();
}
private void InputDetection()
{
dir = Input.GetAxis("Horizontal"); //prendo la direzione
controlThrow = Input.GetAxisRaw("Vertical"); //per il controllo del climbing
checkjump = Input.GetButtonDown("Jump");
}
private void FixedUpdate()
{
Move();
Jump();
FlipSprite();
ClimbLadder();
}
private void Jump()
{
if (!myFeetCollider.IsTouchingLayers(LayerMask.GetMask("Ground"))) { return; }
if (checkjump)
{
Vector2 jumpVelocityToAdd = new Vector2(0f, jumpSpeed);
rb.velocity += jumpVelocityToAdd;
}
}