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; 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; 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, [ World.add(world, [
Bodies.rectangle(200, 150, 400, 20, { isStatic: true, angle: Math.PI * 0.06 }), 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) { Composites.car = function(xx, yy, width, height, wheelSize) {
var group = Body.nextGroup(true), var group = Body.nextGroup(true),
wheelBase = -20, wheelBase = 20,
wheelAOffset = -width * 0.5 + wheelBase, wheelAOffset = -width * 0.5 + wheelBase,
wheelBOffset = width * 0.5 - wheelBase, wheelBOffset = width * 0.5 - wheelBase,
wheelYOffset = 0; wheelYOffset = 0;
var car = Composite.create({ label: 'Car' }), var car = Composite.create({ label: 'Car' }),
body = Bodies.trapezoid(xx, yy, width, height, 0.3, { body = Bodies.rectangle(xx, yy, width, height, {
collisionFilter: { collisionFilter: {
group: group group: group
}, },
friction: 0.01,
chamfer: { chamfer: {
radius: 10 radius: height * 0.5
} },
density: 0.0002
}); });
var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, { var wheelA = Bodies.circle(xx + wheelAOffset, yy + wheelYOffset, wheelSize, {
collisionFilter: { collisionFilter: {
group: group group: group
}, },
friction: 0.8, friction: 0.8
density: 0.01
}); });
var wheelB = Bodies.circle(xx + wheelBOffset, yy + wheelYOffset, wheelSize, { var wheelB = Bodies.circle(xx + wheelBOffset, yy + wheelYOffset, wheelSize, {
collisionFilter: { collisionFilter: {
group: group group: group
}, },
friction: 0.8, friction: 0.8
density: 0.01
}); });
var axelA = Constraint.create({ var axelA = Constraint.create({
bodyA: body, bodyB: body,
pointA: { x: wheelAOffset, y: wheelYOffset }, pointB: { x: wheelAOffset, y: wheelYOffset },
bodyB: wheelA, bodyA: wheelA,
stiffness: 0.2, stiffness: 1,
length: 0,
render: { render: {
lineWidth: 0 lineWidth: 0
} }
}); });
var axelB = Constraint.create({ var axelB = Constraint.create({
bodyA: body, bodyB: body,
pointA: { x: wheelBOffset, y: wheelYOffset }, pointB: { x: wheelBOffset, y: wheelYOffset },
bodyB: wheelB, bodyA: wheelB,
stiffness: 0.2, stiffness: 1,
length: 0,
render: { render: {
lineWidth: 0 lineWidth: 0
} }