Skip to content

How to apply force to rigid bodies? #176

Answered by isaac-mason
drifter089 asked this question in Q&A
Discussion options

You must be logged in to vote

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

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@drifter089
Comment options

@Seanmclem
Comment options

Answer selected by wiledal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested
3 participants