# How to generate a random tunnel consists of series of two line paths

I have a 2D path that follows series of lines thru points p1 p2 p3 p4.

Like this: ___/\__/\___

I want to make a tunnel out of this path, so I need to split this path in two sideways and make a hole inside of it. Like this:

     ________
____/        \_____
_______
____/       \_____



How do I do that?

I actually want to just generate a random tunnel it doesn't have to follow a path.

A simple approach would be to take the 2D path, create a copy of it, so you now have two identical paths on top of one another, then offset the Y-values of one path so they form an upper and lower bound, creating a "tunnel".

example using the path you supplied:

intial path: ___/\__/\___

___/\__/\___
duplicated and offset:
___/\__/\___


There are many methods that would generate a 2D "tunnel", but given that you already have a 2D path this seems the simplest.

• would this work if the path is going downwards, that is negative on the y axis – eguneys Oct 4 '19 at 8:54
• You could determine the slope of the path and then decide whether to offset vertically or horizontally. If the slope of the path is horizontal you offset vertically, if the slope is vertical you offset horizontally. If you have diagonal paths you can offset along the paths normal direction. Your question just mentioned the one horizontal path example so I assumed that was the only use case. If you edit your question to add more info on what you are going for it will be easier to give a complete answer. – disc_code22 Oct 4 '19 at 13:15
• I tried to offset by the normal direction but I got weird results, now I quit game dev. – eguneys Oct 4 '19 at 13:21
• In case you decide to give it another shot here is a near duplicate of your question that answers how to generate 2D tunnels/passageways: gamedev.stackexchange.com/questions/37887/… – disc_code22 Oct 4 '19 at 13:31