P2. JS distance constraint (distanceconstraint) memo

Source: Internet
Author: User

Key code:
1 //here is the code for the ground and the wall2 //under3 varBODY =NewP2. Body ({mass:0, Position: [0, 5]});4 varShape =NewP2. Plane ();5 Body.addshape (shape);6 World.addbody (body);7 8 //Right9BODY =NewP2. Body ({angle:math.pi/2, mass:0, Position: [10, 0]});Ten Body.addshape (shape); One World.addbody (body); A  - //left -BODY =NewP2. Body ({angle:-MATH.PI/2, mass:0, Position: [-10, 0]}); the Body.addshape (shape); - World.addbody (body); -  - //here is the code to constrain the distance of two balls +  varConstraint =NewP2. Distanceconstraint (Circle1, Circle2, { -Distance:3, +Localanchora: [0, 0], ALocalanchorb: [0, 0], at MaxForce:Math.MAX_VALUE - }); - world.addconstraint (constraint); -  -constraint.collideconnected =true; -constraint.lowerlimitenabled =true; inconstraint.upperlimitenabled =true; -Constraint.lowerlimit = 2.5; toConstraint.upperlimit = 4;

Let's first make a memo on the wall code. When the body is initialized, angle is set to MATH.PI/2, which can be seen as rotating the horizontal level counterclockwise (CCW) 90 degrees, and then setting a large x position, forming a right wall. Similarly, when the angle is set to-MATH.PI/2, the horizontal plane rotates 90 degrees clockwise (CW), setting a smaller x position, which is the left wall. Then there are some properties of the distance constraint. Distance, which defines the distance between the Localanchora and Localanchorb two anchor points. Maxforce is the force that the constraint is subjected to. The default value is Math.max_value, at which point you can imagine a hardcore connection between two balls. When the Maxforce is set to a non-maximum value, the equivalent of two balls is connected by a bamboo bar. Collideconnected, if the connected object can collide, the default value is true. This property can be configured with the maxforce above to see the effect together. The Maxforce is set to a smaller value, the binding of the two balls is reduced, by default, the ball may collide, that is, two small balls do not intersect; when collideconnected = False, the two spheres may intersect. Because they are set to not collide. Lowerlimitenabled, uppperlimitenabled, Lowerlimit, Upperlimit, these four properties allow distance constraints to increase the characteristics of similar telescopic pistons. Practice Source Address: https://gist.github.com/yxzblue/3a66babfb93b889f0833#file-distancematerial-html p2.js v0.6.0 package, Link: http ://pan.baidu.com/s/1mgsw7xa Password: Bj85p2.js's github address: https://github.com/schteppe/p2.js

P2. JS distance constraint (distanceconstraint) memo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.