How to make a dynamic wall generation
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!
Your answer
![](https://koobas.hobune.stream/wayback/20220613020045im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Raycast detect in object (problem) 0 Answers
Raycast not drawing where i tell it 1 Answer
am trying to instantiate a 3D object to fly in the direction where my mouse is pointing 0 Answers
raycast activation by trigger 0 Answers
Raycast hit 2 Answers