Skip to content

Commit

Permalink
Density
Browse files Browse the repository at this point in the history
  • Loading branch information
hmans committed Sep 26, 2022
1 parent c0395dc commit 8d95fbe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/dry-planes-applaud.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hmans/physics3d": patch
---

Added `density` prop on collider.
1 change: 1 addition & 0 deletions apps/spacerage/src/scenes/gameplay/Asteroids.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const Asteroids = () => {
>
<group>
<ConvexHullCollider
density={5}
collisionGroups={interactionGroups(Layers.Asteroid, [
Layers.Asteroid,
Layers.Player
Expand Down
11 changes: 9 additions & 2 deletions packages/hmans-physics3d/src/colliders/ConvexHullCollider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import { usePhysicsWorld } from "../World"
import { multiplyByMatrix } from "../util/multiplyByMatrix"

export type ConvexHullColliderProps = {
density?: number
points: Float32Array
collisionGroups?: RAPIER.InteractionGroups
} & GroupProps

function ConvexHullCollider(
{ points, collisionGroups, ...props }: ConvexHullColliderProps,
{ points, collisionGroups, density = 1, ...props }: ConvexHullColliderProps,
ref: ForwardedRef<THREE.Group>
) {
const { world } = usePhysicsWorld()
Expand Down Expand Up @@ -53,7 +54,13 @@ function ConvexHullCollider(
/* Create the collider */
const collider = world.createCollider(desc, rb.body)

if (collisionGroups) collider.setCollisionGroups(collisionGroups)
if (density !== undefined) {
collider.setDensity(density)
}

if (collisionGroups !== undefined) {
collider.setCollisionGroups(collisionGroups)
}

/* Destroy the collider on unmount */
return () => world.removeCollider(collider, true)
Expand Down

0 comments on commit 8d95fbe

Please sign in to comment.