Hey! I am using Cannon as a physics engine (because Ammo.js will not load) in React Native. I have a square using a box imposter that is supposed to drop and hit the ground. These objects are created using:
d6.physicsImpostor = new PhysicsImpostor(d6, PhysicsImpostor.BoxImpostor, { mass: 1, friction: 1, restitution: 0.5 }, scene);
and ground.physicsImpostor = new PhysicsImpostor(ground, PhysicsImpostor.BoxImpostor, { mass: 0, friction: 0.5, restitution: 0.7 }, scene);
Now, what I am expecting to happen is for the dice to bounce and roll over as it does in my proof of concept using webpack. However, when the cube makes contact with the ground plane, it sits there for about 10 seconds then the FPS drops to 0 and the entire app locks up. It’s almost as if the collision calculations on React Native are broken. Has anyone heard of this before? Thanks!
This playground is the expected behavior, however when I take the exact same code and move it to React Native, the cube will fall as gravity is correctly applied, but when it hits the ground plane it freezes, FPS drops to zero, and I am forced to force-kill the app since it becomes unresponsive.
Now that I have switched require('fs') with require('react-native-fs') and added a let document = {}; I get a random error from Ammo saying undefined is not an object (evaluating 'this._tmpAmmoVectorA.setValue').
Thanks for the response! I am loading ammo.js in React Native the same way that I would if I was doing it for the web. First, yarn add kripken/ammo.js, then use the import statement import * as ammo from 'ammo.js';. Finally, I use the following code block to import it:
const gravityVector = new Vector3(0, -9.81, 0);
const Ammo = await ammo();
const ammoPlugin = new AmmoJSPlugin(true, Ammo);
scene.enablePhysics(gravityVector, ammoPlugin);
This does not work by itself on the web version however, and I have to add fallback: { 'fs': false, 'path': false } to the webpack.config.js. In React Native, there is no way to do this, and I get the error unable to load module fs as I mentioned in this post: Can't load Ammo.js Physics Engine in React Native. Thanks for taking a look!
ABSOLUTE LEGEND!! I had tried using react-native-fs before but never react-native-path - react-native-path was the missing link! Thank you so much for your help!!!
Edit:
I renamed the thread since that is what it ended up being.