mirror of
https://github.com/liabru/matter-js.git
synced 2024-12-17 12:42:17 -05:00
improved Example.chains using pin constraint
This commit is contained in:
parent
0e15099479
commit
9d2f0ffb5b
1 changed files with 24 additions and 7 deletions
|
@ -39,7 +39,7 @@ Example.chains = function() {
|
|||
// add bodies
|
||||
var group = Body.nextGroup(true);
|
||||
|
||||
var ropeA = Composites.stack(200, 100, 4, 2, 10, 10, function(x, y) {
|
||||
var ropeA = Composites.stack(100, 50, 8, 1, 10, 10, function(x, y) {
|
||||
return Bodies.rectangle(x, y, 50, 20, { collisionFilter: { group: group } });
|
||||
});
|
||||
|
||||
|
@ -47,15 +47,13 @@ Example.chains = function() {
|
|||
Composite.add(ropeA, Constraint.create({
|
||||
bodyB: ropeA.bodies[0],
|
||||
pointB: { x: -25, y: 0 },
|
||||
pointA: { x: 200, y: 100 },
|
||||
pointA: { x: ropeA.bodies[0].position.x, y: ropeA.bodies[0].position.y },
|
||||
stiffness: 0.5
|
||||
}));
|
||||
|
||||
World.add(world, ropeA);
|
||||
|
||||
group = Body.nextGroup(true);
|
||||
|
||||
var ropeB = Composites.stack(500, 100, 5, 2, 10, 10, function(x, y) {
|
||||
var ropeB = Composites.stack(350, 50, 10, 1, 10, 10, function(x, y) {
|
||||
return Bodies.circle(x, y, 20, { collisionFilter: { group: group } });
|
||||
});
|
||||
|
||||
|
@ -63,11 +61,30 @@ Example.chains = function() {
|
|||
Composite.add(ropeB, Constraint.create({
|
||||
bodyB: ropeB.bodies[0],
|
||||
pointB: { x: -20, y: 0 },
|
||||
pointA: { x: 500, y: 100 },
|
||||
pointA: { x: ropeB.bodies[0].position.x, y: ropeB.bodies[0].position.y },
|
||||
stiffness: 0.5
|
||||
}));
|
||||
|
||||
World.add(world, ropeB);
|
||||
group = Body.nextGroup(true);
|
||||
|
||||
var ropeC = Composites.stack(600, 50, 13, 1, 10, 10, function(x, y) {
|
||||
return Bodies.rectangle(x - 20, y, 50, 20, { collisionFilter: { group: group }, chamfer: 5 });
|
||||
});
|
||||
|
||||
Composites.chain(ropeC, 0.3, 0, -0.3, 0, { stiffness: 1, length: 0 });
|
||||
Composite.add(ropeC, Constraint.create({
|
||||
bodyB: ropeC.bodies[0],
|
||||
pointB: { x: -20, y: 0 },
|
||||
pointA: { x: ropeC.bodies[0].position.x, y: ropeC.bodies[0].position.y },
|
||||
stiffness: 0.5
|
||||
}));
|
||||
|
||||
World.add(world, [
|
||||
ropeA,
|
||||
ropeB,
|
||||
ropeC,
|
||||
Bodies.rectangle(400, 600, 1200, 50.5, { isStatic: true })
|
||||
]);
|
||||
|
||||
// add mouse control
|
||||
var mouse = Mouse.create(render.canvas),
|
||||
|
|
Loading…
Reference in a new issue