P2.JS之距离约束(DistanceConstraint)备忘
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;
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。