0 Favourites

# Trying to fill the gaps created from making a random tunnel

• 4 posts
• Hi!

I'm trying to make a tunnel-game that is randomly generated. I'll create a tiled background then angle it random(-10,+10) and then create a new segment at the end of it. Works great but the problem is just doing that leaves these ugly gaps between them:

I think I can fix it with a "Move at angle" but I don't know how to figure out how far to move it back.

Any help?

Develop games in your browser. Powerful, performant & highly capable.

Construct 3 users don't see these ads
• You could try moving each piece left by 100*sin(self.angle) pixels or something. You'll probably want to tweak 100 till it looks right.

Here's the general idea below. If there are still gaps increase 100 to something bigger.

global number prevAngle=0

global number prevX=0

global number prevY=240

global number turn=0

start of layout

repeat 10 times

set turn to random(-10,10)

create tiledbg at (tiledbg.x, tiledbg.y)

tiledbg: set angle to prevAngle+turn

tiledbg: move tiledbg.width-100*sin(turn) pixels at prevAngle degrees

set prevAngle to tiledbg.angle

set prevX to tiledbg.x

set prevY to tiledbg.y

• Hey YetAnotherSuperhero,

One possible approach might be, rather than rotating the next segment around the middle of the edge, make each segment rotate around whichever corner is on the outer side of the bend.

This way you don't have to fix gaps after the fact by moving things, since there will never be gaps in the first place.

e.g.

If the tunnel is moving rightward, then when the tunnel bends down, you rotate the next segment around the top corner.

When the tunnel bends up, you rotate around the bottom corner.

This means the tunnel segments will always be fully overlapping where they join.

Here is an example capx.

GaplessWindingPath

In this example, the path segments have been made semi-transparent, so you can see how they overlap.

• R0J0hound fisholith Thanks! I'll give these a look.

• 4 posts