Contact force
Monitor and react to contact forces applied to rigid bodies during collisions.
Contact force events are triggered after the physics solver computes forces between two colliders. Unlike collisions, contact force events don't fire on enter/exit — they fire every simulation step while two bodies remain in contact and the accumulated force exceeds a configurable threshold.
<RigidBody activeContactForce @contact-force="onContactForce">
<TresMesh>
<TresSphereGeometry />
<TresMeshNormalMaterial />
</TresMesh>
</RigidBody>
You need to set the
activeContactForce prop to receive contact force events.contactForceEventThreshold
Because contact force events fire every simulation step, it's often useful to filter out low-force contacts. Set contactForceEventThreshold to only receive events when the total force magnitude exceeds the given value (defaults to 5.0).
<RigidBody
activeContactForce
:contact-force-event-threshold="100"
@contact-force="onContactForce"
>
<TresMesh>
<TresSphereGeometry />
<TresMeshNormalMaterial />
</TresMesh>
</RigidBody>
Events
contact-force
(payload: ContactForcePayload) => void
Triggered every simulation step while two colliders are in contact and the force exceeds the threshold.
ContactForcePayload
source
SourceTarget
The rigid body and collider that has
activeContactForce enabled.target
SourceTarget
The other rigid body and collider involved in the contact.
totalForce
Vector
The sum of all contact forces between the two colliders, as a 3D vector.
totalForceMagnitude
number
The scalar magnitude of
totalForce.maxForceDirection
Vector
The direction of the largest individual contact force.
maxForceMagnitude
number
The magnitude of the largest individual contact force.