This is a maintained fork of cannon.js, originally created by Stefan Hedman @schteppe.
It's a type-safe flatbundle (esm and cjs) which allows for tree shaking and usage in modern environments.
These minor changes and improvements were also made:
ConvexPolyhedron
constructor now accepts an object instead of a list of arguments. #6Cylinder
is now oriented on the Y axis. #30type
property of the Cylinder
is now equal to Shape.types.CYLINDER
. #59Body.applyImpulse()
and Body.applyForce()
are now relative to the center of the body instead of the center of the world 86b0444World.hasActiveBodies: boolean
which will be false when all physics bodies are sleeping. This allows for invalidating frames when physics aren't active for increased performance.World.frictionGravity: Vec3
which can be set to customize the force used when computing the friction between two colliding bodies. If undefined
, World.gravity
will be used. This property is useful to enable friction in zero gravity. This addresses issue #224 and follows the pattern established for p2.js.If instead you're using three.js in a React environment with react-three-fiber, check out use-cannon! It's a wrapper around cannon-es.
yarn add cannon-es
import { World } from 'cannon-es'
// ...
or, if you're using webpack, you can import it like this while still taking advantage of tree shaking:
import * as CANNON from 'cannon-es'
// ...
as any
assertions, and remove as any
type assertions wherever possible