I'm developing a simple 2d platform game with Unity 2d. I have a problem managining my "Jump" action for the player.
I would like the player to Jump only when he has his feet on a "surface": terrain, platform, crate etc.
I'm considering using colliders: when my player collides with a surface, set my
bool canJump = true.
When he jumps, I set
canJump = false (he is midair).
My terrain has a
Kinematic and a
Box Collider 2d.
My Player has a
Dynamic and a
Capsule Collider 2d (or a Polygon Collider.. )
OnTriggerEnter2d() are never raised when Player collides with terrain.
Does anyone know what's wrong?
EDIT: Now i'm using this to check if "something" is under my feet:
RaycastHit2D hit = Physics2D.Raycast(rb.transform.position, -Vector2.up, 0.1f); if (hit) canJump = true;
It doesn't works! hit is always true! I'm getting mad!