Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Cannon.js uses the MKS system of units (meter-kilogram-second). To correctly set gravity to 9.8 m/s/s, you do:</p> <pre><code>world.gravity.set(0,-9.8,0); </code></pre> <p>(assuming "up" direction is along the positive Y axis.)</p> <p>For the mass calculation, you could do something like this:</p> <pre><code>var density = 2515; // kg/m^3 var mass = density * shape.volume(); // M=p*V </code></pre> <p>Then use this mass when creating your stone bodies.</p> <p>If you are aiming for a game with real time physics, you may have to let go of the "correct" physical properties to increase physics performance. You can do that by changing gravity and masses, adding damping, limiting maximum velocity of bodies, etc.. There are no specific guidelines for this, but there are a number of tricks.</p> <p>Regarding materials: In general you create a new <code>CANNON.Material</code> for each material you have in your scene. Then you create a <code>CANNON.ContactMaterial</code> that defines what happens when a pair of these materials meet. Here's sample code, but see the <a href="http://schteppe.github.io/cannon.js/demos/friction.html" rel="noreferrer">friction demo</a> for a full example.</p> <pre><code>var slipperyMat = new CANNON.Material(); var friction = 0.0; var restitution = 0.2; var slipperyContact = new CANNON.ContactMaterial(slipperyMat,slipperyMat,friction,restitution); world.addContactMaterial(slipperyContact); </code></pre> <p>If you only plan to have one type of material, you can set properties on the default contact material in the world instead. Have a look at <code>world.defaultContactMaterial</code>.</p> <p>The sponginess question is a good one. If you want to hang on to your physically correct masses, gravity, etc., you probably need to increase precision a bit. You can do that by using a smaller time step (for example, try using two half steps per rendering frame) and/or tweaking the contact solving settings:</p> <pre><code>world.solver.iterations = 20; // Increase solver iterations (default is 10) world.solver.tolerance = 0; // Force solver to use all iterations // Adjust constraint equation parameters: use to tweak sponginess slipperyContact.contactEquationStiffness = 1e8; slipperyContact.contactEquationRegularizationTime = 3; </code></pre> <p>The stiffness and regularization controls the "sponginess" of the contacts. If you use large stiffness and small regularization, the solver will try to make less spongy contacts for you. Provided enough solver precision (small time step and lots of iterations), you will get a better solution.</p> <p>I've assumed Cannon.js 0.6.0 (dev branch at the moment) throughout this answer.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload