0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-12-24 13:29:01 -05:00

improved Example.car using pin constraint

This commit is contained in:
liabru 2017-05-03 21:26:40 +01:00
parent b277b39940
commit 130e6b3f56
2 changed files with 19 additions and 19 deletions

View file

@ -42,10 +42,10 @@ Example.car = function() {
]);
var scale = 0.9;
World.add(world, Composites.car(150, 100, 100 * scale, 40 * scale, 30 * scale));
World.add(world, Composites.car(150, 100, 150 * scale, 30 * scale, 30 * scale));
scale = 0.8;
World.add(world, Composites.car(350, 300, 100 * scale, 40 * scale, 30 * scale));
World.add(world, Composites.car(350, 300, 150 * scale, 30 * scale, 30 * scale));
World.add(world, [
Bodies.rectangle(200, 150, 400, 20, { isStatic: true, angle: Math.PI * 0.06 }),

View file

@ -239,53 +239,53 @@ var Bodies = require('./Bodies');
*/
Composites.car = function(xx, yy, width, height, wheelSize) {
var group = Body.nextGroup(true),
wheelBase = -20,
wheelBase = 20,
wheelAOffset = -width * 0.5 + wheelBase,
wheelBOffset = width * 0.5 - wheelBase,
wheelYOffset = 0;
var car = Composite.create({ label: 'Car' }),
body = Bodies.trapezoid(xx, yy, width, height, 0.3, {
body = Bodies.rectangle(xx, yy, width, height, {
collisionFilter: {
group: group
},
friction: 0.01,
chamfer: {
radius: 10
}
radius: height * 0.5
},
density: 0.0002
});
var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, {
collisionFilter: {
group: group
},
friction: 0.8,
density: 0.01
friction: 0.8
});
var wheelB = Bodies.circle(xx + wheelBOffset, yy + wheelYOffset, wheelSize, {
collisionFilter: {
group: group
},
friction: 0.8,
density: 0.01
friction: 0.8
});
var axelA = Constraint.create({
bodyA: body,
pointA: { x: wheelAOffset, y: wheelYOffset },
bodyB: wheelA,
stiffness: 0.2,
bodyB: body,
pointB: { x: wheelAOffset, y: wheelYOffset },
bodyA: wheelA,
stiffness: 1,
length: 0,
render: {
lineWidth: 0
}
});
var axelB = Constraint.create({
bodyA: body,
pointA: { x: wheelBOffset, y: wheelYOffset },
bodyB: wheelB,
stiffness: 0.2,
bodyB: body,
pointB: { x: wheelBOffset, y: wheelYOffset },
bodyA: wheelB,
stiffness: 1,
length: 0,
render: {
lineWidth: 0
}