I’m running into a weird issue when trying to determine where the player is hitting on a hitbox.
I am using this code to detect a collision and then determine if they hit the wall or the floor part of a block.
private void OnCollisionEnter2D(Collision2D collision)
{
//First, check if it is the ground or not.
if(collision.gameObject.tag == "Ground")
{
Vector2 colVect = collision.contacts[0].normal;
Debug.Log(colVect);
//Now, check if it is the wall or the floor. So we check contacts.
if (colVect == Vector2.up)
{
//We're on the floor! :smile:
isGrounded = true;
isJumping = false;
Debug.Log("Floor!");
}
else if(colVect == Vector2.left || colVect == Vector2.right)
{
//We're hitting a wall!
touchingWall = true;
Debug.Log("Wall!");
}
else
{
Debug.Log("THINGS FUCKED!");
}
}
}
My problem is, that sometimes apparently Vector2.up isn’t equal to 0.00, 1.00, even though it totally is?
Using my debug output, I get the following instances:
(0.00, 1.00)
THINGS FUCKED!
(0.00, 1.00)
Floor!
(0.00, 1.00)
Floor!
(0.00, 1.00)
THINGS FUCKED!
Where the (0.00, 1.00) is the Debug.Log(colVect) and the text is what part of the if/else it ends up in.
Any idea why this is happening? (0.00, 1.00) should always be equal to Vector2.up, but sometimes it doesn’t go into the if statement for some reason?