Skip to content

Is there any ways to get the RigidBody's position? #480

Closed Answered by wiledal
arkk200 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes!

See: https://github.com/pmndrs/react-three-rapier#moving-things-around-and-applying-forces

RigidBodies are returned as RefObject containing a Rapier RigidBody, so you can use all the functions available here:
https://rapier.rs/javascript3d/classes/RigidBody.html

You access it by getting it in a ref.

import { RapierRigidBody } from "@react-three/rapier";

const Object = () => {
  const rigidBody = useRef<RapierRigidBody>(null);

  useEffect(() => {
    if (rigidBody.current) {
      const position = rigidBody.current.translation()
      const rotation = rigidBody.current.rotation()
    }
  }, []);

  return (
    <RigidBody ref={rigidBody}>
      <mesh>
        <boxBufferGeometry />

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by arkk200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants