From b70ce12ec92edeaf67d4deebeb795946a6935dcc Mon Sep 17 00:00:00 2001
From: Paul Mathieu
Date: Sat, 25 Dec 2021 08:22:39 -0800
Subject: [PATCH] Adjust gravity and jump force
---
game.js | 12 ++++++++++--
index.html | 9 +++++++++
index.js | 2 ++
3 files changed, 21 insertions(+), 2 deletions(-)
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:
+
+