Skip to content

Commit

Permalink
improved Example.car using pin constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
liabru committed May 3, 2017
1 parent b277b39 commit 130e6b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions examples/car.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
Expand Down
34 changes: 17 additions & 17 deletions src/factory/Composites.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 130e6b3

Please sign in to comment.