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.


1 Answer 1


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.

  • \$\begingroup\$ would this work if the path is going downwards, that is negative on the y axis \$\endgroup\$
    – eguneys
    Oct 4, 2019 at 8:54
  • \$\begingroup\$ 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. \$\endgroup\$ Oct 4, 2019 at 13:15
  • \$\begingroup\$ I tried to offset by the normal direction but I got weird results, now I quit game dev. \$\endgroup\$
    – eguneys
    Oct 4, 2019 at 13:21
  • \$\begingroup\$ 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/… \$\endgroup\$ Oct 4, 2019 at 13:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .