@threlte/rapier
Version:
Components and hooks to use the Rapier physics engine in Threlte
12 lines (11 loc) • 510 B
JavaScript
import { Vector3 } from 'three';
import { useJoint } from './useJoint';
import { isVector3 } from './utils';
export const useSphericalJoint = (anchorA, anchorB) => {
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.spherical(jaA, jaB);
return world.createImpulseJoint(params, rbA, rbB, true);
});
};