0
\$\begingroup\$

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.

\$\endgroup\$
0
\$\begingroup\$

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.

\$\endgroup\$
  • \$\begingroup\$ would this work if the path is going downwards, that is negative on the y axis \$\endgroup\$ – eguneys Oct 4 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\$ – disc_code22 Oct 4 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 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\$ – disc_code22 Oct 4 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.