Hi, Im new to unity. Everytime I hold the jump button my character stucks under the ceiling. How can I fix this? I want that the character falls down, it should not stuck under the ceiling.
using UnityEngine;
public class Movement : MonoBehaviour
{
private Rigidbody2D rb;
public float speed = 10;
public float Jumpforce = 10;
private void Start()
{
rb = GetComponent<Rigidbody2D>();
}
private void FixedUpdate()
{
var movement = Input.GetAxis("Horizontal");
transform.position += new Vector3(movement, 0, 0) * Time.deltaTime * speed;
if (Input.GetButton("Jump") && Mathf.Abs(rb.velocity.y) < 0.001f)
{
rb.AddForce(new Vector2(0, Jumpforce), ForceMode2D.Impulse);
}
}
}