@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/dist/declarations/src/Physics.d.ts +10 -2
- package/dist/declarations/src/types.d.ts +25 -13
- package/dist/declarations/src/utils-collider.d.ts +1 -1
- package/dist/react-three-rapier.cjs.dev.js +348 -246
- package/dist/react-three-rapier.cjs.prod.js +348 -246
- package/dist/react-three-rapier.esm.js +349 -247
- package/package.json +1 -1
- package/readme.md +39 -0
package/package.json
CHANGED
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.
|