so basically it works fine on flat ground but if it interacts with a sloped tile like a rock it only has a 50/50 chance of letting my player jump, any help would be greatly appreciated.
void Start()
{
rb = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>();
}
// Update is called once per frame
void Update()
{
Move();
Jump();
CheckIfGrounded();
}
void Move()
{
float moveInput = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(moveInput * speed, rb.velocity.y);
if (moveInput == 0)
{
anim.SetBool("isRunning", false);
}
else
{
anim.SetBool("isRunning", true);
}
if (moveInput < 0)
{
transform.eulerAngles = new Vector3(0, 180, 0);
}
else if (moveInput > 0)
{
transform.eulerAngles = new Vector3(0, 0, 0);
}
}
void Jump()
{
if (Input.GetKeyDown(KeyCode.Space) && isGrounded)
{
rb.velocity = new Vector2(rb.velocity.x, jumpForce);
anim.SetTrigger("Jump");
}
}
void CheckIfGrounded()
{
Collider2D collider = Physics2D.OverlapCircle(isGroundedChecker.position, checkGroundRadius, groundLayer);
if (collider != null)
{
isGrounded = true;
anim.SetBool("IsJumping", false);
}
else
{
isGrounded = false;
anim.SetBool("IsJumping", true);
}
}
}