How to apply force to rigid bodies? #176
Answered
by
isaac-mason
drifter089
asked this question in
Q&A
-
I can;t figure out how to apply force to rigid bodies |
Beta Was this translation helpful? Give feedback.
Answered by
isaac-mason
Nov 19, 2022
Replies: 1 comment 2 replies
-
You can apply forces to a rigid body using the ref of a RigidBody component. e.g. const ExampleRigidBodyComponent = (props) => {
const ref = useRef()
useEffect(() => {
ref.current.addForce({ x: 0, y: 1, z: 0 }, true)
}, [])
return (
<RigidBody ref={ref}>
{ /* ... */ }
</RigidBody>
)
} Here's a related sandbox that shows how to use a rigid body component's ref (in this example an impulse is applied on clicking a box) https://codesandbox.io/s/react-three-rapier-applyimpulse-8nuh3m |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
wiledal
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can apply forces to a rigid body using the ref of a RigidBody component.
e.g.
Here's a related sandbox that shows how to use a rigid body component's ref (in this example an impulse is applied on clicking a box)
https://codesandbox.io/s/react-three-rapier-applyimpulse-8nuh3m