add interpolation

This commit is contained in:
Asraelite 2016-03-24 01:09:29 +00:00
parent 1412cabbb4
commit df3f0d1436
3 changed files with 9 additions and 5 deletions

View file

@ -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]);