From df3f0d1436c4f13656e09dc2ff5ae473ac82a775 Mon Sep 17 00:00:00 2001 From: Asraelite Date: Thu, 24 Mar 2016 01:09:29 +0000 Subject: [PATCH] add interpolation --- public/js/starbugs/world/asteroid.js | 2 +- public/js/starbugs/world/physics.js | 10 +++++++--- public/js/starbugs/world/ship.js | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/public/js/starbugs/world/asteroid.js b/public/js/starbugs/world/asteroid.js index 5fb7251..135007c 100644 --- a/public/js/starbugs/world/asteroid.js +++ b/public/js/starbugs/world/asteroid.js @@ -27,7 +27,7 @@ function Asteroid(data) { this.yvel = data[3]; this.r = data[4]; this.rvel = data[5]; - this.updated = true; + this.updated = 10; }; this.tick = function() { diff --git a/public/js/starbugs/world/physics.js b/public/js/starbugs/world/physics.js index c7658c9..b43214a 100644 --- a/public/js/starbugs/world/physics.js +++ b/public/js/starbugs/world/physics.js @@ -73,12 +73,16 @@ function Physics() { for (var i in game.world.bodies) { var s = SCALE; + var r = 0.1; var body = game.world.bodies[i]; - if (!body.updated) continue; - body.b2body.SetPositionAndAngle(new b2Vec2(body.x, body.y), body.r); + var pos = body.getPos(); + var x = (body.x * r + pos.x) / (r + 1); + var y = (body.y * r + pos.y) / (r + 1); + var r = (body.r * r + pos.r) / (r + 1); + if (body.updated-- <= 0) continue; + body.b2body.SetPositionAndAngle(new b2Vec2(x, y), r); body.b2body.SetLinearVelocity(new b2Vec2(body.xvel, body.yvel)); body.b2body.SetAngularVelocity(body.rvel); - body.updated = false; } for (var i = 0; i < this.toRemove.length; i++) { this.world.DestroyBody(this.toRemove[i]); diff --git a/public/js/starbugs/world/ship.js b/public/js/starbugs/world/ship.js index c0b0001..9c2532b 100644 --- a/public/js/starbugs/world/ship.js +++ b/public/js/starbugs/world/ship.js @@ -45,7 +45,7 @@ function Ship(data) { this.yvel = data[3]; this.r = data[4]; this.rvel = data[5]; - this.updated = true; + this.updated = 10; this.thrust = { forward: data[6], left: data[7],