2D player not jumping

I am having a problem with getting my player to jump. The input is working the ground check is working but the player still won't jump

Give us something to work with. we don't know how you're trying to jump, anything about the code, etc.

This is also not classified as a bug but instead user error.

1 Like

here's the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;

public class playerMovment : MonoBehaviour
{
public int playerSpeed;
public int playerHealth;
public int jumpPower;
public Rigidbody2D rb;
private float horizontalMovement;
private bool isFacingRight;
public LayerMask ground;
public Transform groundCheck;
// Start is called before the first frame update
void Start()
{

}

// Update is called once per frame
void Update()
{
rb.velocity = new Vector2 (horizontalMovement * playerSpeed, rb.velocity.y);

if (!isFacingRight && horizontalMovement < 0f)
{
flip();
}
else if (isFacingRight && horizontalMovement > 0f)
{
flip();
}
}

public void jump(InputAction.CallbackContext context)
{
if (context.performed && isGrounded())
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * jumpPower);
Debug.Log("jump");
}
else if (context.canceled && rb.velocity.y > 0f)
{
rb.velocity = new Vector2(rb.velocity.x, rb.velocity.y * 0.5f);
}
}

private bool isGrounded()
{
return Physics2D.OverlapCircle(groundCheck.position,0.2f,ground);
}

private void flip()
{
isFacingRight = !isFacingRight;
Vector2 localscale = transform.localScale;
localscale.x *= -1f;
transform.localScale = localscale;
}

public void Move(InputAction.CallbackContext context)
{
horizontalMovement = context.ReadValue().x;
}
}

As you already know, please don't post code as plain text. Always use code-tags.

You need to debug your code. You cannot simply post it and hope others can debug it for you. You've sprinkled it with debug.logs but don't state what's output. Also, you're not debugging what you're using as arguments i.e. what forces, velocities etc. You can attached a debugger and do this or just output them. Knowing you called a method is not enough.

This is not likely to be a physics issue but a script issue.

Thanks.

1 Like

i'll give you a hint, when you multiply a number the result changes drastically based on the second value. zero for example