I’m currently making a platformer game and I have an issue with Physics. When I jump on a wall and holding A/D then the player doesn’t fall until I stop holding A/D. All platforms in my game have ground layer, rigidbody and tilemap collider (because I’m working with tilemaps).
Here is my code:
[SerializeField] private float speed;
[SerializeField] private float jumpForce;
[SerializeField] private LayerMask groundLayer;
private bool canJump;
private Vector3 inputVector;
private Rigidbody2D rb;
private void Awake()
{
rb = GetComponent<Rigidbody2D>();
}
private void Update()
{
Movement();
Jump();
}
private void Movement()
{
rb.velocity = new Vector2(Input.GetAxis("Horizontal") * speed, rb.velocity.y);
}
private void Jump()
{
CheckGround();
if (Input.GetKeyDown(KeyCode.Space) && canJump)
{
rb.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}
}
private void CheckGround()
{
float boxDist = 1f;
float boxAngle = 0f;
canJump = Physics2D.BoxCast(transform.position, Vector2.one, boxAngle,
Vector2.down, boxDist, groundLayer);
}