diff options
| -rw-r--r-- | public/assets/javascripts/app.js | 5 | ||||
| -rw-r--r-- | public/assets/javascripts/mx/extensions/mx.movements.js | 27 |
2 files changed, 20 insertions, 12 deletions
diff --git a/public/assets/javascripts/app.js b/public/assets/javascripts/app.js index f8372cd..cfbe4bf 100644 --- a/public/assets/javascripts/app.js +++ b/public/assets/javascripts/app.js @@ -57,11 +57,14 @@ app.launch = function () { } app.movements.init() + var last_t = 0 function animate (t) { + var dt = t - last_t + last_t = t requestAnimationFrame(animate) environment.update(t) window.path && path.update(t) - app.movements.update() + app.movements.update(dt || 0) scene.update() } diff --git a/public/assets/javascripts/mx/extensions/mx.movements.js b/public/assets/javascripts/mx/extensions/mx.movements.js index 5b1e2de..2993fb6 100644 --- a/public/assets/javascripts/mx/extensions/mx.movements.js +++ b/public/assets/javascripts/mx/extensions/mx.movements.js @@ -254,7 +254,7 @@ MX.Movements = function (cam) { } }, - update: function () { + update: function (dt) { if (locked) { return } @@ -263,6 +263,11 @@ MX.Movements = function (cam) { var vrrrr = creeping ? vr * creepFactor * 5 : vr * 0.5 var moving = moveForward || moveBackward || moveRight || moveLeft || moveUp || moveDown || turnLeft || turnRight || turnUp || turnDown vx = vz = 0 + + var vv = v +// vv *= dt / 100 * 8 +// s *= dt / 100 * 8 +// console.log(dt / 100 * 8) pos.x = cam.x pos.z = cam.z @@ -270,26 +275,26 @@ MX.Movements = function (cam) { if (moving) { if (moveForward) { - vx += v * Math.cos(ry + Math.PI / 2) * s - vz += v * Math.sin(ry + Math.PI / 2) * s + vx += vv * Math.cos(ry + Math.PI / 2) * s + vz += vv * Math.sin(ry + Math.PI / 2) * s } if (moveBackward) { - vx -= v * Math.cos(ry + Math.PI / 2) * s - vz -= v * Math.sin(ry + Math.PI / 2) * s + vx -= vv * Math.cos(ry + Math.PI / 2) * s + vz -= vv * Math.sin(ry + Math.PI / 2) * s } if (moveLeft) { - vx -= v * Math.cos(ry) * s - vz -= v * Math.sin(ry) * s + vx -= vv * Math.cos(ry) * s + vz -= vv * Math.sin(ry) * s } if (moveRight) { - vx += v * Math.cos(ry) * s - vz += v * Math.sin(ry) * s + vx += vv * Math.cos(ry) * s + vz += vv * Math.sin(ry) * s } if (moveUp) { - pos.y += v * scale + pos.y += vv * scale } if (moveDown) { - pos.y -= v * scale + pos.y -= vv * scale } if (turnUp) { |
