@react-three/rapier 0.8.2 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-three/rapier",
3
- "version": "0.8.2",
3
+ "version": "0.9.0",
4
4
  "source": "src/index.ts",
5
5
  "main": "dist/react-three-rapier.cjs.js",
6
6
  "module": "dist/react-three-rapier.esm.js",
package/readme.md CHANGED
@@ -296,6 +296,45 @@ When the second argument is omitted, the collider will interact with all groups:
296
296
 
297
297
  > **Note** By default, colliders are members of all groups, and will interact with all other groups.
298
298
 
299
+ ## Contact force events
300
+
301
+ Contact force events are triggered on `<RigidBody>` and any collider components when two objects collider.
302
+
303
+ ```tsx
304
+ <RigidBody
305
+ colliders="ball"
306
+ onContactForce={(payload) => {
307
+ console.log(`The total force generated was: ${payload.totalForce}`);
308
+ }}>
309
+ <Sphere>
310
+ <meshPhysicalMaterial color={'grey'}>
311
+ </Sphere>
312
+ </RigidBody>
313
+ ```
314
+
315
+ The payload for the contact force event contains the following properties:
316
+
317
+ `rigidBody` - The rigid body of the other colliding rigid body
318
+ `collider` - The other collider
319
+ `rigidBodyObject` - The THREE `Object3D` instance of the other rigid body object
320
+ `colliderObject` - The THREE `Object3D` instance of the other collider object
321
+ `totalForce` - The sum of all the forces between the two colliders
322
+ `totalForceMagnitude` - The sum of the magnitudes of each force between the two colliders
323
+ `maxForceDirection` - The magnitude of the largest force at a contact point of this contact pair
324
+ `maxForceMagnitude` - The world-space (unit) direction of the force with strongest magnitude
325
+
326
+ More information about each property can be found in the rapier [TempContactForceEvent API documentation](https://rapier.rs/javascript3d/classes/TempContactForceEvent.html).
327
+
328
+ You can also add the `onContactForce` event to any collider.
329
+
330
+ ```tsx
331
+ <CapsuleCollider
332
+ onContactForce={(payload) => {
333
+ /* ... */
334
+ }}
335
+ />
336
+ ```
337
+
299
338
  ## Sensors
300
339
 
301
340
  A Collider can be set to be a sensor, which means that it will not generate any contact points, and will not be affected by forces. This is useful for detecting when a collider enters or leaves another collider, without affecting the other collider.