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

Get help using Construct 2

### » Sun Nov 08, 2015 1:13 am

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?
B
34
S
14
G
4
Posts: 251
Reputation: 4,074

### » Sun Nov 08, 2015 5:09 am

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
B
95
S
34
G
128
Posts: 5,495
Reputation: 81,678

### » Sun Nov 08, 2015 9:07 am

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.
B
28
S
18
G
8
Posts: 333
Reputation: 6,193

### » Mon Nov 09, 2015 1:05 am

@R0J0hound @fisholith Thanks! I'll give these a look.
B
34
S
14
G
4
Posts: 251
Reputation: 4,074