threlte logo
@threlte/rapier

useCollisionGroups

This hook can be used in conjunction with the component <CollisionGroups>. It uses the collision groups provided by a parent <CollisionGroups> component and lets you easily apply them to colliders.

<script>
	import { useRapier, useCollisionGroups } from '@threlte/rapier'

	const { world } = useRapier()
	const { registerColliders, removeColliders } = useCollisionGroups()

	const collider = world.createCollider(…)

	// collider will be assigned the collision groups
	// provided by a parent `<CollisionGroups>` component.
	registerColliders([collider])

	onDestroy(() => {
		removeColliders([collider])
	})
</script>

Types

const {
  registerColliders, // (colliders: RAPIER.Collider[]) => void
  removeColliders // (colliders: RAPIER.Collider[]) => void
} = useCollisionGroups()