- Home /

# How to connect walls corners

Hello, I have no idea how to connect corners of walls. Im making walls by new mesh and stretching them to mouse position. It would be nice if I could connect walls by mesh but I dont know how to do this. Maybe someboy could help me with this. There can be many walls connected.

**Answer** by JonPQ
·
Aug 15, 2019 at 07:40 PM

easy question, complex answer.... depends if in 2d or 3d.... but possibilities.... 1) just push them into each other, and let z-buffer take car of the intersections. (this still won't be able to add extra geometry where you have sketched) 2) if your pieces always fit at pre defined angles.... e.g most rooms have right angles, then build a corner piece you can use at the intersecting corners. 3) do some very complex boolean geometry intersection code, that can build new geometry. (this still won't be able to add extra geometry where you have sketched) 4) if your images are flat (hard to tell from screen shot) you could build in a rounded end to the texture at each end.... then when they overlap, the round parts would match. 5) add a nub. some kind of joint object that you put at each corner (works for 2D and 3D) a 3D wall would be a tall pillar( think of castle wall towers at angles in the wall) . for 2D it might be a Circular sprite. then the walls are stuffed into or below your nub. It hides the join, but you'll have a nub at each joint/corner, which you might not visually want. there are probably more ways...

**Answer** by Pakillottk
·
Aug 17, 2019 at 05:08 PM

Hi. I think that you could to it generating a new mesh procedurally. If your walls are always making paths made of simple polylines (no curves, just straight lines) you'll have two scenarios: 90º corner in "L" shape, non 90º corners in "V" shape. So, in order to close the corner you'll need 4 points (in the 2D case, in 3D you'll need 8, four for the floor and four for the ceiling). Think about this (i'm really bad drawing but I hope that you can get the idea):

So you have the two walls meeting, each wall has the exterior and interior part (outter and inner). Then you'll get the 4 points this way:

The exact point between the two walls (in the inner part)

If you make a line perpendicular to the inner wall segment from the point 1 to the left (+90º), then it'll cut the outter wall segment in this point.

The exact point between the two walls (in the outter part)

If you make a line perpendicular to the inner wall segment from the point 1 to the right (-90º), then it'll cut the outter wall segment in this point.

So your corner will be a mesh with the two triangles: 1-3-2 and 1-4-3. This will work for both cases.

If you agree that this is the right solution for your problem then I'll also suggest that you avoid entirely intersection calculations and so on, becase I assume that you know the distance between the inner and the outter walls, therefore you can get points 2 and 4 with simple vector math which is fast and cheap in comparison with intersection math.

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.