- Home /
How to check if a grid unit position has a tile from the Tile Palette placed on it?
I'm working on grid based game like Bomberman:
While starting the stage, I wanna run a code that generates destructible squares randomly , treating all of it as a matrix of sorts. I have most of the code ready to do it, BUT I don't know how to check if the actual position of the grid where I'm about to instantiate a destructible wall has already been ocuppied by a tile placed by the Tile Palette.
I've tried using Raycast to do the check while only searching for the layer of the grid, but hit returns "ok" even though I'm not aiming at one of those placements:
(The graybackground it's not part of palette and it's in another layer).
Any of you has any idea of how I could progress? Here's my RayCast code, if it's worth checking:
raycastStartingPosition.position = matrixUpperLeftEdge.position;
Vector2 temporaryRaycastPos = matrixUpperLeftEdge.position;
int layerMask = 1 << 12;
RaycastHit raycastHit;
if (!Physics.Raycast(raycastStartingPosition.position, Vector3.forward, out raycastHit, 50, layerMask)) {
Debug.DrawRay(raycastStartingPosition.position, Vector3.forward * 1000, Color.green);
print("hit");
} else {
Debug.DrawRay(raycastStartingPosition.position, Vector3.forward * 1000, Color.red);
}
Thanks in advance.
Answer by MSavioti · Oct 11, 2018 at 08:14 AM
It was a dumb mistake of mine and I won't delete the question because it may prove useful to someone in the future, but the problem was that I forgot that I put the "!" in the if condition as a part of the logic.
My bad.