I’m using the following code to check ground. But it fail when the character is jumping and fall touching a wall because the code only detect a normal at the same time (i think so).
So i need my variable to be “isGrounded=true” only when boxcollider touch de tilemap on the up side. So, is there some way to solve this problem?
Thank you so much!!
//---------------------------------------------------
private void OnCollisionExit2D(Collision2D collision)
{
if (collision.CompareTag("Tilemap"))
{
state.isGrounded = false;
if (move == Movement.idle || state.isRuning)
{
state.isJumping = false;
state.isGrounded = true;
return;
}
state.isJumping = true;
}
}
//---------------------------------------------------
private void OnCollisionEnter2D(Collision2D collision)
{
//let jump
if (move == Movement.up) return;
int index = 0;
while (index < collision.contactCount)
{
Vector3 normal = collision.GetContact(index).normal;
Sides side = new Sides();
side.AnalizeNormal(normal);
if (side.up)
{
state.isJumping = false;
state.isGrounded = true;
}
//Debug.Log(this + " " + side.up + " " + side.right + " " + side.left + " " + side.down);
index++;
}
;
}
///----------------------------------------------------
public void AnalizeNormal(Vector3 normal)
{
if (normal.x > 0.1f)
{
right = true;
}
else if (normal.x < -0.1f)
{
left = true;
}
if (normal.y > 0.1f)
{
up = true;
}
else if (normal.y < -0.1f)
{
down = true;
}
}