UNPKG

@threlte/rapier

Version:

Components and hooks to use the Rapier physics engine in Threlte

15 lines (14 loc) 586 B
import { Vector3 } from 'three'; import { useJoint } from './useJoint'; import { isVector3 } from './utils'; /** * The rope joint limits the max distance between two bodies. */ export const useRopeJoint = (anchorA, anchorB, length) => { return useJoint((rbA, rbB, { world, rapier }) => { const jaA = isVector3(anchorA) ? anchorA : new Vector3(...anchorA); const jaB = isVector3(anchorB) ? anchorB : new Vector3(...anchorB); const params = rapier.JointData.rope(length, jaA, jaB); return world.createImpulseJoint(params, rbA, rbB, true); }); };