Answer the question
In order to leave comments, you need to log in
Why is the character always jumping to different heights in a platformer?
if (hit.collider != null)
{
Debug.Log(hit.collider.gameObject.name);
if (isGrounded() && hit.collider.gameObject.name != "Player")
{
rigidbody2D.AddForce(Vector2.up * jumpForce, ForceMode2D.Impulse);
}
}
private bool isGrounded()
{
float extraHeight = 0.1f;
RaycastHit2D raycastHitGround = Physics2D.Raycast(boxCollider2D.bounds.center, Vector2.down, boxCollider2D.bounds.extents.y + extraHeight);
Color rayColor;
if (raycastHitGround.collider != null)
{
rayColor = Color.green;
}
else
{
rayColor = Color.red;
}
Debug.DrawRay(boxCollider2D.bounds.center, Vector2.down * (boxCollider2D.bounds.extents.y + extraHeight));
return raycastHitGround.collider != null;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question