mirror of
https://github.com/liabru/matter-js.git
synced 2025-01-13 16:18:50 -05:00
improved Example.catapult using pin constraint
This commit is contained in:
parent
130e6b3f56
commit
0e15099479
1 changed files with 13 additions and 4 deletions
|
@ -9,7 +9,9 @@ Example.catapult = function() {
|
||||||
MouseConstraint = Matter.MouseConstraint,
|
MouseConstraint = Matter.MouseConstraint,
|
||||||
Mouse = Matter.Mouse,
|
Mouse = Matter.Mouse,
|
||||||
World = Matter.World,
|
World = Matter.World,
|
||||||
Bodies = Matter.Bodies;
|
Bodies = Matter.Bodies,
|
||||||
|
Body = Matter.Body,
|
||||||
|
Vector = Matter.Vector;
|
||||||
|
|
||||||
// create engine
|
// create engine
|
||||||
var engine = Engine.create(),
|
var engine = Engine.create(),
|
||||||
|
@ -35,20 +37,27 @@ Example.catapult = function() {
|
||||||
Runner.run(runner, engine);
|
Runner.run(runner, engine);
|
||||||
|
|
||||||
// add bodies
|
// add bodies
|
||||||
|
var group = Body.nextGroup(true);
|
||||||
|
|
||||||
var stack = Composites.stack(250, 255, 1, 6, 0, 0, function(x, y) {
|
var stack = Composites.stack(250, 255, 1, 6, 0, 0, function(x, y) {
|
||||||
return Bodies.rectangle(x, y, 30, 30);
|
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, [
|
World.add(world, [
|
||||||
stack,
|
stack,
|
||||||
catapult,
|
catapult,
|
||||||
Bodies.rectangle(400, 600, 800, 50.5, { isStatic: true }),
|
Bodies.rectangle(400, 600, 800, 50.5, { isStatic: true }),
|
||||||
Bodies.rectangle(250, 555, 20, 50, { 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 }),
|
Bodies.circle(560, 100, 50, { density: 0.005 }),
|
||||||
Constraint.create({ bodyA: catapult, pointB: { x: 390, y: 580 } }),
|
Constraint.create({
|
||||||
Constraint.create({ bodyA: catapult, pointB: { x: 410, y: 580 } })
|
bodyA: catapult,
|
||||||
|
pointB: Vector.clone(catapult.position),
|
||||||
|
stiffness: 1,
|
||||||
|
length: 0
|
||||||
|
})
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// add mouse control
|
// add mouse control
|
||||||
|
|
Loading…
Reference in a new issue