From 0e1509947917e11a18416eba2a51e90e4a315b7c Mon Sep 17 00:00:00 2001 From: liabru Date: Wed, 3 May 2017 21:28:39 +0100 Subject: [PATCH] improved Example.catapult using pin constraint --- examples/catapult.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/examples/catapult.js b/examples/catapult.js index 64c4965..7fa0809 100644 --- a/examples/catapult.js +++ b/examples/catapult.js @@ -9,7 +9,9 @@ Example.catapult = function() { MouseConstraint = Matter.MouseConstraint, Mouse = Matter.Mouse, World = Matter.World, - Bodies = Matter.Bodies; + Bodies = Matter.Bodies, + Body = Matter.Body, + Vector = Matter.Vector; // create engine var engine = Engine.create(), @@ -35,20 +37,27 @@ Example.catapult = function() { Runner.run(runner, engine); // add bodies + var group = Body.nextGroup(true); + var stack = Composites.stack(250, 255, 1, 6, 0, 0, function(x, y) { return Bodies.rectangle(x, y, 30, 30); }); - var catapult = Bodies.rectangle(400, 520, 320, 20); + var catapult = Bodies.rectangle(400, 520, 320, 20, { collisionFilter: { group: group } }); World.add(world, [ stack, catapult, Bodies.rectangle(400, 600, 800, 50.5, { isStatic: true }), Bodies.rectangle(250, 555, 20, 50, { isStatic: true }), + Bodies.rectangle(400, 535, 20, 80, { isStatic: true, collisionFilter: { group: group } }), Bodies.circle(560, 100, 50, { density: 0.005 }), - Constraint.create({ bodyA: catapult, pointB: { x: 390, y: 580 } }), - Constraint.create({ bodyA: catapult, pointB: { x: 410, y: 580 } }) + Constraint.create({ + bodyA: catapult, + pointB: Vector.clone(catapult.position), + stiffness: 1, + length: 0 + }) ]); // add mouse control