- Home /
Procedual Wall Generation
I was doing some coding for my game recently, and I was wondering how you would going about doing procedural walls like shown in Software Inc. Currently, I have a system where you place a point in the world, that point is added to a list, walls are drawn between the points, and if the tiles (stationed between the world points) have the corresponding flag to them (!upwards, !downwards, !diagonal) then you may place the points. I was wondering 3 things.
How would I go about upgrading this system to include diagonal walls
How do I check if one wall runs into the other wall
How would I go about finding the area between the walls and trigger the corresponding indoors flags?
Thank you for your time
Answer by jaspercayne · May 03, 2016 at 09:37 AM
I would be storing the start and end coords of each wall, then it isn't too big a deal to just find a mid point and draw your wall between the start and end, just follow the diagonal direction you want the wall placed in.
By storing the walls start, end, and direction you just need to check if a wall's intended path would cross between start and end.
Since you've been saving the walls coordinates, you are really just checking the coordinates of your game object are in the bounds of the corners drawn by the outer walls. Possibly consider making colliders on the walls that extend much further than the width of the wall. Then you would just have to check if the object is touching all respective colliders and you know you are inside. If you have roofs it's absolute gravy. Just raycast up the appropriate distance from floor to ceiling, and if you hit the roof, you're indoors.
Thanks for the help!
For some clarification, currently I have it set up so that the wall spawns between the two points, and scales to the length between the two points, and then looks at the first point and rotates 90 degrees. However I have no idea how to do the math to find the correct tile. Currently here is my code for finding the tile and deter$$anonymous$$ing if the Diagonal Wall Used flag is active:
for (float i = 0; i < $$anonymous$$athf.Sqrt($$anonymous$$athf.Pow(Pos1.x-Pos2.x, 2)+$$anonymous$$athf.Pow(Pos1.z-Pos2.z, 2)); i+=0.05f) {
if(worldInit.World.GrabTile(new Vector3(i + Pos1.x, 0, i*((Pos1.z-Pos2.z)/(Pos1.x-Pos2.x)) + Pos1.z)).DiagnalWallUsed){
Result = false;
}
}
For number 2 and 3 thank you for your assistance!
You can use transform.position to get a vector3 of the position of the object in the scene, where x and z are the horizontal coordinates and y is the vertical. 0,0,0 is the center of the scene, 3 dimensionally.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Drunkard Walk Algorithm C# Question 0 Answers
How to apply A* algorithm in C#? 2 Answers
Disable Mac OSX 'Active Screen Corners' 2 Answers