Skip to content

Instantly share code, notes, and snippets.

@GraemeFulton
Created July 25, 2015 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save GraemeFulton/e84198c9fe53b4dab5c6 to your computer and use it in GitHub Desktop.
Save GraemeFulton/e84198c9fe53b4dab5c6 to your computer and use it in GitHub Desktop.
Moving forwards - when camera moves past a tile, move it right to the front
/**
* createTerrainMatrix
* @TODO: create the matrix of terrains - need to add 9 bits of terrain
*/
createTerrainMatrix:function(scene, perlinNoise){
//every 100px on the z axis, add a bit of ground
for ( var z= 100; z > -200; z-=100 ) {
//Create the perlin noise for the surface of the ground
var perlinSurface = new PerlinSurface(perlinNoise, 100, 100);
var ground = perlinSurface.surface;
//rotate 90 degrees around the xaxis so we can see the terrain
ground.rotation.x = -Math.PI/-2;
// Then set the z position to where it is in the loop (distance of camera)
ground.position.z = z;
ground.position.y -=4;
//add the ground to the scene
scene.add(ground);
//finally push it to the floor array
this.floor.push(ground);
}
},
/**
* moveWithCamera
* when the camera gets past the first terrain, put the other in front of it
*/
moveWithCamera(camera){
// loop through each star
for(var i=0; i<this.floor.length; i++) {
//if the camera has moved past the entire square, move the square
if((this.floor[i].position.z - 100)>camera.position.z){
this.floor[i].position.z-=200;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment