Infinite 2D Terrain Generation

Hey all, I have seen a couple of the regulars here talking about / experimenting with 3D infinite terrain. I’ve achieved 2D Terrain using the same sort of expression using Perlin noise. This is successful and looks great for different hills and generation, but at the moment I’m having to create a chain body with 200 points in it then triangulate these 200 points. As you’ve guessed by now, this takes considerably longer at start up and well, it’s finite. I wanted to ask you guys do you think it’s possible with the current box2D implemented in Codea to create an infinite 2D Terrain (e.g hill climb racing, tiny wings) without the lag of creating a body with 200 points or triangulating all those points at once.

Also another question, as the TLL team said (John I think) the new Box2D implementation will have a great speed boost, what do you mean by great? Will I be able to create 20 bodies in one frame without lag?

Tiny wings type game by @pepinganos in codea

Are you talking about 3d terrain as in, full 3d volumetric, or as in a 2d heightmap with height values (2.5d)?

It’s definitely possible anyways to make procedurally generated infinite terrain - you just need to generate the terrain in small chunks. Also, perlin noise may be a bit overkill - especially in 1.5d generation, the difference between say midpoint displacement (I made a nice implementation you can check out on CC), and Perlin noise is pretty small, in terms of quality.

I can easily generate terrain using my implementation using say, 7 passes, which gives really good quality with no percieveable pause on an ipad 2.

I don’t see why you’d need to triangulate 200 points anyways - seems a bit overkill.

2D Side scrolling terrain, just a 2D with height map for now I can add effects after to make it look better than just a line. I was looking at midpoint displacement as a method as well, it looks more efficient than perlin noise. I use 200 points to make the ground completely smooth over around 6000 units

Using midpoint displacement, at eight iterations it creates 257 points nearly instantly (the point count is always a power of 2 + 1)

This isn’t the problem, the speed of the algorithm is fine. The chain body creation and triangulation of points is the problem. But generally it seems midpoint displacement is quite a bit faster.

I would actually like to see how this turns out… Sounds like something that could be useful for my Zombie game

@CodeaNoob it depends, I can’t generate all of it at once, but I can’t have it remove what’s not on the screen as that would be the easy method which is why the game West linked to isn’t sufficient. The reason is if I have a few boxes in my game (this is at the moment a procedural terrain generation for my builder game to test inventions such as cars or a big sled (the creative stuff I come up with) and go down at a slight gradient hill with noise for hill ranges, but if it deletes what is behind me on the terrain then bodies behind me will fall down through the ground when I need it to not do that, obviously.

I’m now rethinking it and it does need to be finite, but long, real long, about a 1 minute drive. What I have at the moment can do that, but I fear for my iPads safety because it can crash easily from creating it all in one frame.

Use coroutines to spread the triangulation over multiple frames, so there is no pause or freeze.

Also, i don’t understand why having stuff behind you fall through the floor etc is an issue - you aren’t going to be able to go back and see this, right?

No you can go back, it’s an open 2D world where you make what you want limited by box2D capability. I’ll use the coroutines actually didn’t think of that!

I’ve updated my CC Midpoint Displacement project to use coroutines, btw.

Hi. I made a small example creating a heightmap for 3d landscape with perlin noise.

need some more work to make it infinite though…

@tnlogy that’s cool, I haven’t started with 3D terrain yet but I’m thinking of moving to that next after I finished my game.

@tnlogy is it normal that I only get a grey background?xo

Then I guess my code breaks :). Try decreasing the s value in Terrain:init and move your ipad down since it uses rotationrate

@tnlogy still nothing xo

Edit: nevermind, I have a project to test stuff in, and mostly I just paste stuff in the main tab… But i didn’t realise one of the previous projects created a Terrain class in a seperate class
I just deletet that, looking nice