diff --git a/game.js b/game.js index 6256b73..75bfeb2 100644 --- a/game.js +++ b/game.js @@ -71,6 +71,7 @@ function handleKeys(params) { const ori = se3.roty(params.camera.orientation[1]); const tf = se3.apply(ori, dir); const maxSpeed = 0.1; + const airMovement = 0.08; if (params.flying) { params.camera.position[0] += tf[0]; @@ -80,14 +81,16 @@ function handleKeys(params) { params.camera.velocity[0] = tf[0]; params.camera.velocity[2] = tf[2]; } else { - params.camera.velocity[0] += tf[0] / 60; - params.camera.velocity[2] += tf[2] / 60; + const vel = params.camera.velocity; - if (Math.abs(params.camera.velocity[0]) > maxSpeed) { - params.camera.velocity[0] = Math.sign(params.camera.velocity[0]) * maxSpeed; - } - if (Math.abs(params.camera.velocity[2]) > maxSpeed) { - params.camera.velocity[2] = Math.sign(params.camera.velocity[2]) * maxSpeed; + vel[0] += tf[0] * airMovement; + vel[2] += tf[2] * airMovement; + + const curVel = Math.sqrt(vel[0] * vel[0] + vel[2] * vel[2]); + + if (curVel > maxSpeed) { + vel[0] *= maxSpeed / curVel; + vel[2] *= maxSpeed / curVel; } } }; diff --git a/world.js b/world.js index c1cbff3..013c56e 100644 --- a/world.js +++ b/world.js @@ -115,9 +115,10 @@ function makeChunk(z, x) { data.set(Array(waterHeight - currentHeight).fill(BlockType.WATER), offset + currentHeight); currentHeight = waterHeight; } else { - data[offset + grassHeight - 1] = BlockType.GRASS; if (hasATree(seed, z + i, x + j)) { trees.push([i, j, currentHeight]); + } else { + data[offset + grassHeight - 1] = BlockType.GRASS; } } data.set(Array(256 - currentHeight).fill(BlockType.AIR), offset + currentHeight);