diff --git a/game.js b/game.js index 75bfeb2..83595f5 100644 --- a/game.js +++ b/game.js @@ -160,7 +160,7 @@ function getObjects(world, z, x, glContext) { } function updatePhysics(params) { - params.camera.velocity[1] -= 9.8 / 60 / 60; + params.camera.velocity[1] += params.gravity / 60 / 60; const oldPos = params.camera.position; const targetPos = params.flying ? oldPos : params.camera.position.map((v, i) => v + params.camera.velocity[i]); @@ -243,6 +243,14 @@ export function setupParamPanel(params) { document.querySelector('#ambiant').oninput = e => { params.ambiantLight = e.target.value / 100; }; + document.querySelector('#gravity').oninput = e => { + params.gravity = e.target.value; + document.querySelector('#gravityValue').textContent = e.target.value; + }; + document.querySelector('#jumpForce').oninput = e => { + params.jumpForce = e.target.value / 100; + document.querySelector('#jumpForceValue').textContent = e.target.value / 100; + }; const collapsibles = document.getElementsByClassName("collapsible"); for (const collapsible of collapsibles) { @@ -309,7 +317,7 @@ export function initUiListeners(params, canvas) { case 'Space': if (!params.flying) { if (params.jumpAmount > 0) { - const amount = 0.08; + const amount = params.jumpForce; params.camera.velocity[1] = amount; params.jumpAmount -= 1; } diff --git a/index.html b/index.html index dc7e027..4cf6fcb 100644 --- a/index.html +++ b/index.html @@ -63,6 +63,15 @@

+
+

Physics

+

+ Gravity: +

+

+ Jump force: +

+
diff --git a/index.js b/index.js index 45c735f..4854e2d 100644 --- a/index.js +++ b/index.js @@ -28,6 +28,8 @@ async function main() { isOnGround: false, world: makeWorld(), worldGl: await initWorldGl(gl), + gravity: -17, + jumpForce: 0.11, } setupParamPanel(params);