CANNON is not defined in React

import *as Cannon from ‘cannon’
var gravityVector = new BABYLON.Vector3(0, -9.81, 0);
var physicsPlugin = new BABYLON.CannonJSPlugin();
scene.enablePhysics(gravityVector, physicsPlugin);

How to use cannon in react——BABYLON??how?


I’m a beginner and went through this problem.

I ended up using cannonjs and babylonjs outside react and I am very happy like this. If you still want to use cannonjs with react there is this : react-babylonjs - npm

In case anyone encounters the same problem, you can try passing cannon’s reference to CannonJSPlugin.


import cannon from ‘cannon’;

scene.enablePhysics(new Vector3(0, -9.81, 0), new CannonJSPlugin(true, 10, cannon));