I’m just trying to use the raycast2d for the collision detection, the ray is going down, so it should work only when it falls on something, but for some reason it sets onGround to true even when it collides on the side, why it’s doing that?
EDIT : I tried adding a number to it Physics2D.Raycast(transform.position, - Vector2.up, 1), but the problem is still there.
void OnCollisionStay2D(Collision2D obj)
{
// Cast a ray straight down.
var hit: RaycastHit2D = Physics2D.Raycast(transform.position, - Vector2.up);
// If it hits something...
if (hit != null) {
onGround = true;
}
}
void OnCollisionExit2D(Collision2D obj)
{
grounded = false;
}