I am embarrassed to ask this question, because it’s too easy and I’m disappointed in myself that I actually got stuck on this. My simple 2D jump script doesn’t work, specifically the Rigidbody2D.AddForce() line is the problem. Here’s the code:
public Rigidbody2D rb;
public float jumpHeight = 10f;
public bool canJump = false;
void Awake()
{
rb = gameObject.GetComponent<Rigidbody2D>();
}
void Update()
{
if (Input.GetButtonDown("Jump") && canJump == true && rb != null)
{
//rb.velocity = Vector2.up * jumpHeight;
//rb.AddForce(new Vector2(0f, jumpHeight), ForceMode2D.Impulse);
rb.AddForce(Vector2.up * jumpHeight * Time.deltaTime);
Debug.Log("This Debug.Log line actually gets written in the console, so the problem is not with the if statement.");
}
}
Here are my Rigidbody2D settings:
