Skip to content

Commit 95ae911

Browse files
committed
fixed friction in Demo.manipulation
1 parent 4491dfd commit 95ae911

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

demo/js/Demo.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -445,12 +445,16 @@
445445
Body.setVertices(bodyE, bodyE.vertices);
446446
}
447447

448-
// make bodyA move up and down and rotate constantly
449-
Body.setPosition(bodyA, { x: 100, y: 300 + 100 * Math.sin(_engine.timing.timestamp * 0.005) });
450-
Body.rotate(bodyA, 0.02);
448+
// make bodyA move up and down
449+
// body is static so must manually update velocity for friction to work
450+
var py = 300 + 100 * Math.sin(_engine.timing.timestamp * 0.002);
451+
Body.setVelocity(bodyA, { x: 0, y: py - bodyA.position.y });
452+
Body.setPosition(bodyA, { x: 100, y: py });
451453

452454
// make compound body move up and down and rotate constantly
453-
Body.setPosition(compound, { x: 600, y: 300 + 100 * Math.sin(_engine.timing.timestamp * 0.005) });
455+
Body.setVelocity(compound, { x: 0, y: py - compound.position.y });
456+
Body.setAngularVelocity(compound, 0.02);
457+
Body.setPosition(compound, { x: 600, y: py });
454458
Body.rotate(compound, 0.02);
455459

456460
// every 1.5 sec

0 commit comments

Comments
 (0)