What is happening now, is that the raycast detects de player itsself, so it is always grounded. So you need to add a LayerMask, so the raycast doesn't detect the player.
After adding this it looks like this:
/*Code*/
public LayerMask layerMask;
/*Code*/
void FixedUpdate()
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, -Vector2.up, 0.5f, layerMask);
grounded = hit.collider != null;
}
In the editor set the player to another layer (just add new layer "Player" or something) and go to the layermask and select all except the "Player" layermask.
↧