- Home /
Physics2D Overlapbox not working as aspected
Hey Guys,
I'm doing some A* Pathfinding right now and causing some issues with Tilemap and Physics2D.OverlapBox. I created a nodemap, which contains nodes. To find out, which node is walkable and which node not, I'm looking for colliders, which are at nodes position, to determine, if the node is walkable or not. Unfortunaly, Physics2D.OverlapBox not working as aspected.
What I did so far: Tilemap has some Composite2D Collider, where Mode is changed to polygons If i change the size of the overlap box to new Vector2(1,1) its working fine, but when I change it back to my code (below) it do not detect any collider. If I change to Physics2D.OverlapArea it will find a collider. I tried to fix this issue for hours, but didnt fine any solution yet. Maybe you guys could help me.
Code: public float nodeSize = 0.5f;
public void CheckNodeMap()
{
for (int x = 0; x < nodeMap.GetLength(0); x++)
{
for (int y = 0; y < nodeMap.GetLength(1); y++)
{
bool isWalkable = true;
isWalkable = Physics2D.OverlapBoxAll(new Vector2(transform.position.x + (x * nodeSize) + nodeSize / 2, transform.position.y + (y * nodeSize) + nodeSize / 2), new Vector2(nodeSize-0.05f, nodeSize-0.05f) / 2,0,9).Length > 0 ? false : isWalkable;
nodeMap[x, y].isWalkable = isWalkable;
}
}
}
Your answer
Follow this Question
Related Questions
Is there a standardized way for creating a 2D ball physics movement method? 0 Answers
Should a physics material be added to the collider or the rigidbody? 2 Answers
How to make slider joint immovable by the player 1 Answer
Horizontal attraction? 0 Answers
Two Polygon2D Collider do not Collide with Each Other (Solved) 2 Answers