From 95ae911ed60a9bd3cbefefdbd06b126d7edf87c5 Mon Sep 17 00:00:00 2001 From: liabru Date: Sat, 9 May 2015 21:25:01 +0100 Subject: [PATCH] fixed friction in Demo.manipulation --- demo/js/Demo.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/demo/js/Demo.js b/demo/js/Demo.js index cd869a5..c99c19f 100644 --- a/demo/js/Demo.js +++ b/demo/js/Demo.js @@ -445,12 +445,16 @@ Body.setVertices(bodyE, bodyE.vertices); } - // make bodyA move up and down and rotate constantly - Body.setPosition(bodyA, { x: 100, y: 300 + 100 * Math.sin(_engine.timing.timestamp * 0.005) }); - Body.rotate(bodyA, 0.02); + // make bodyA move up and down + // body is static so must manually update velocity for friction to work + var py = 300 + 100 * Math.sin(_engine.timing.timestamp * 0.002); + Body.setVelocity(bodyA, { x: 0, y: py - bodyA.position.y }); + Body.setPosition(bodyA, { x: 100, y: py }); // make compound body move up and down and rotate constantly - Body.setPosition(compound, { x: 600, y: 300 + 100 * Math.sin(_engine.timing.timestamp * 0.005) }); + Body.setVelocity(compound, { x: 0, y: py - compound.position.y }); + Body.setAngularVelocity(compound, 0.02); + Body.setPosition(compound, { x: 600, y: py }); Body.rotate(compound, 0.02); // every 1.5 sec