- Home /
Rotating quads and check if 2 sides touch another quad
Hi, all. I'm new to unity and I'm loving it so far. I've successfully wandered around it and learned quite a bit, but I am looking for a couple of specific functions to do what I need.
Basically, I created a script which I put onto a empty GameObject which randomly generates a array X * Y, and from there procedurally creates a "house" persay with doors, rooms, walkways, map boundaries, and the like.
http://i.imgur.com/d9UxVfM.png
As you can see it works fairly well for being whipped up in a short amount of time (did the generation code in C then ported to C# for unity).
My problem is, when I use cubes it works fine and there are no gaps or anything out of the ordinary, which is fine, but cubes are bulky and not very wall like. This is where I though of using quads.
http://i.imgur.com/jX4c6y6.png http://i.imgur.com/pnQPK16.png (sorry for a bad screenshot of the problem but you can sort of see it)
When using quads, they are all on edge like walls which is great, but they all face east/west. What I need to figure out is how to rotate specific quads so that some are facing east/west and the others are facing north/south to create walls. Another problem I for see is the quads are centered in the squad grid, so I would also need to position them on the right side and the top side of the square grid.
There is no way to tell which way walls should be facing programmically from my generation code (unless i revamp it), so I have to do it through unity and and rotate and check if it fits into place.
Here is the sample of how my Array looks like printed out to terminal so you have an idea of what I'm working with.
http://i.imgur.com/2xtKTRt.png
X are boundaries, # are walls, + are doors, . are floors/corridors. As you can see there is no way to tell a east/west wall from a north/south wall unless I add in a new symbol as I generate the map.
Hopefully someone can point me to a few functions/code samples which could lead to a solution to this.
PROBLEM: Need to rotate north/south facing walls 90 degrees so they mate with east/west facing walls, as well as move them to the right side/top side of the square grid.
Potential solutions (I think) Recode part of my level generation script to use a different symbol for the two walls, so I can simply draw different walls when I spawn them.
Or
Figure out if the wall is a north/south wall via unity objects, and rotate them.
Thanks for any help and sorry for the long question, I tried to provide as much information as I could without dumping 500 lines of code on here.
I agree with @GhastAvitor that you likely don't want quads for this purpose. Quads are one sided with the use of most shaders, which means that if you look at the back side, they quad disappears. I don't know your use for these walls, but quads are also one sided with respect to collisions. You can scale boxes boxes to be thinner, but you will have to solve the problem of identifying N/S vs E/W to know which axis to scale.
Answer by GhastAvaitor · May 24, 2014 at 12:00 AM
Go back to cubes. You can rescale them via code and make them less bulky. Quads are not good for walls, they are good for 2D or menus. That is about it.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Twin Stick Shooter controller 0 Answers
RotateAround Limitations 2 Answers
Rotating sprite through touch (storing current rotation) 0 Answers
Sphere rotation in moving direction 1 Answer