I have a game where you can build your own place and stuff, you can make a custom layout of the place and all, the thing is, i can't figure out how to dynamically create the walls, i tried with Raycasts and if the ray detects another floor tile next to him then checks a bool indicating that can't generate a wall in that space:
void CheckForWalls()
{
RaycastHit hitU;
RaycastHit hitD;
RaycastHit hitL;
RaycastHit hitR;
if (!Physics.Raycast(new Vector3(box.bounds.center.x, box.bounds.center.y, box.bounds.max.z), transform.TransformDirection(Vector3.forward), out hitU, distance))
occupiedUp = true;
if (!Physics.Raycast(new Vector3(box.bounds.center.x, box.bounds.center.y, box.bounds.min.z), transform.TransformDirection(Vector3.back), out hitD, distance))
occupiedDown = true;
if (!Physics.Raycast(new Vector3(box.bounds.max.x, box.bounds.center.y, box.bounds.center.z), transform.TransformDirection(Vector3.left), out hitL, distance))
occupiedLeft = true;
if (!Physics.Raycast(new Vector3(box.bounds.min.x, box.bounds.center.y, box.bounds.center.z), transform.TransformDirection(Vector3.right), out hitR, distance))
occupiedRight = true;
}
I don't know if it's because the floors are detecting each other, but there are some occasions where the detection doesn't work really well. All kind of help is appreciated!
↧