-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add activeCollisionTypes prop to RigidBody and Collider compone…
…nts (#678) * feat: add activeCollisionTypes prop to RigidBody and Collider components * chore: add changeset * chore: cleanup ActiveCollisionTypesExample * fix: revert unintentional version bumps * feat: organise imports * fix: revert unintentional version bumps * chore: change @react-three/rapier-addons to depend on @react-three/rapier ^1.3.1
- Loading branch information
1 parent
a155277
commit 1dc78d0
Showing
5 changed files
with
94 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@react-three/rapier": patch | ||
--- | ||
|
||
feat: add `activeCollisionTypes` prop to RigidBody and Collider components |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
demo/src/examples/active-collision-types/ActiveCollisionTypesExample.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { ActiveCollisionTypes } from "@dimforge/rapier3d-compat"; | ||
import { Box, Sphere } from "@react-three/drei"; | ||
import { useFrame } from "@react-three/fiber"; | ||
import { RapierRigidBody, RigidBody } from "@react-three/rapier"; | ||
import { useRef, useState } from "react"; | ||
|
||
const activeCollisionTypes = | ||
ActiveCollisionTypes.DEFAULT | ActiveCollisionTypes.KINEMATIC_FIXED; | ||
|
||
const Ball = () => { | ||
const rb = useRef<RapierRigidBody>(null); | ||
|
||
const [color, setColor] = useState("blue"); | ||
|
||
useFrame(({ clock: { elapsedTime } }) => { | ||
if (!rb.current) return; | ||
|
||
rb.current.setTranslation( | ||
{ x: Math.sin(elapsedTime) * 3, y: 0, z: 0 }, | ||
true | ||
); | ||
}); | ||
|
||
return ( | ||
<RigidBody | ||
ref={rb} | ||
colliders="ball" | ||
type="kinematicPosition" | ||
activeCollisionTypes={activeCollisionTypes} | ||
onCollisionEnter={() => setColor("green")} | ||
onCollisionExit={() => setColor("blue")} | ||
> | ||
<Sphere> | ||
<meshStandardMaterial color={color} /> | ||
</Sphere> | ||
</RigidBody> | ||
); | ||
}; | ||
|
||
const Wall = () => { | ||
return ( | ||
<RigidBody type="fixed" colliders="cuboid"> | ||
<Box args={[0.5, 5, 2]}> | ||
<meshStandardMaterial color="white" transparent opacity={0.5} /> | ||
</Box> | ||
</RigidBody> | ||
); | ||
}; | ||
|
||
export const ActiveCollisionTypesExample = () => { | ||
return ( | ||
<group> | ||
<Ball /> | ||
<Wall /> | ||
</group> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters