- Home /
Why Physics2D.OverlapArea do not interact with tilemap?
Hi everyone who is reading this. I stuck with a problem when make simple logic in 2d platformer game. I use a tilemap to make a scene, now i have the tilemap with TilemapCollider, compositeCollider and platformEffector2D components. I have a code for jumps, it adds a impulse when "space" is pressed, but i want to allow the jump only when character stay on the ground. So i use OverlapArea function that checks if the area below my character collides with ground (tile). Collider2D hit = Physics2D.OverlapArea(Corner1, Corner2); - hit is always null, even when i see that character is on the ground and it should recognize the collision. Also i have to not that i have used a polygon collider on the background sprite (i used a cinemachine camera) and OverlapArea work with it, but i do not need that, because it is collide even when the character is not on the ground. So what i should do to make my character recognize if it grounded or no?
Answer by Wishade · Nov 24, 2019 at 03:22 PM
So, i found the answer, or no, not the explanation but the way to fix it. By many experiments i have found that the promlem is in the CompositeCollider2D, if you using it and want it to get recognized by OverlapArea - change Geometry Type to "polygons" instead of outlines. Now it is working in my project.