标签:
1 //以下是地面和墙壁的代码 2 //下 3 var body = new p2.Body({ mass: 0, position: [0, -5]}); 4 var shape = new p2.Plane(); 5 body.addShape(shape); 6 world.addBody(body); 7 8 //右 9 body = new p2.Body({ angle: Math.PI / 2, mass: 0, position: [10, 0]}); 10 body.addShape(shape); 11 world.addBody(body); 12 13 //左 14 body = new p2.Body({ angle: -Math.PI / 2, mass: 0, position: [-10, 0]}); 15 body.addShape(shape); 16 world.addBody(body); 17 18 //以下是将两个小球进行距离约束的代码 19 var constraint = new p2.DistanceConstraint(circle1, circle2, { 20 distance: 3, 21 localAnchorA: [0, 0], 22 localAnchorB: [0, 0], 23 maxForce: Math.MAX_VALUE 24 }); 25 world.addConstraint(constraint); 26 27 constraint.collideConnected = true; 28 constraint.lowerLimitEnabled = true; 29 constraint.upperLimitEnabled = true; 30 constraint.lowerLimit = 2.5; 31 constraint.upperLimit = 4;
P2.JS之距离约束(DistanceConstraint)备忘
标签:
原文地址:http://www.cnblogs.com/yxzblue/p/4291177.html