Hi,
I’m trying to convert the following method from a pathfinder script to something that would work in a 2D game with 2D objects.
void CreateGrid() {
grid = new Node[gridSizeX,gridSizeY];
Vector3 worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x/2 -
Vector3.forward * gridWorldSize.y/2;
for (int x = 0; x < gridSizeX; x ++) {
for (int y = 0; y < gridSizeY; y ++) {
Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter +
nodeRadius) + Vector3.forward * (y * nodeDiameter + nodeRadius);
**bool walkable = !(Physics.CheckSphere(worldPoint,nodeRadius,unwalkableMask));**
grid[x,y] = new Node(walkable,worldPoint, x,y);
}
}
}
I have tried to use;
void CreateGrid()
{
grid = new Node[gridSizeX, gridSizeY];
Vector3 worldBottomLeft = transform.position - Vector3.right * gridWorldSize.x / 2 - new Vector3 (0,1,0) * gridWorldSize.y / 2;
for (int x = 0; x < gridSizeX; x++)
{
for (int y = 0; y < gridSizeY; y++)
{
Vector3 worldPoint = worldBottomLeft + Vector3.right * (x * nodeDiameter + nodeRadius) +
new Vector3 (0,1,0) * (y * nodeDiameter + nodeRadius);
**BoxCollider2D bc = gameObject.AddComponent<BoxCollider2D>() as BoxCollider2D;
bool walkable = !(Physics2D.IsTouchingLayers(bc, unwalkableMask));**
grid[x, y] = new Node(walkable, worldPoint, x, y);
print(walkable);
}
}
}
currently bool walkable is returning true ( or false if i remove !) so the bc boxcollider is not touching unwalkable layer.
I’m well out my depth here. Trying to convert a pathfinder script to 2D. I can give more info but I need some help if poss. Thanks.