Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
UseGesture Dragging moves to middle of screen in R3F

I'm using useGuesture and to make some elements draggable in R3F.

When I start dragging (or even click the element) it moves to the center of the screen before it is then possible to drag it around.

How can I get it to drag from it's current position?

This is some code I've got from https://maxrohde.com/2019/10/19/creating-a-draggable-shape-with-react-three-fiber/ and tried to get it to work with objects that do not start in center of screen.

export default function Draggable(props) {
  const [position, setPosition] = useState(props.position);
  const { size, viewport } = useThree();
  const aspect = size.width / viewport.width;

  const bind: any = useGesture(
    {
      onDrag: ({ event, offset: [x, y] }) => {
        const [, , z] = position;
        setPosition([x / aspect, -y / aspect, z]);
      },
      onDragEnd: event => {
        props.onMove(position);
      },
      onClick: props.onClick,
    },
    { drag: { filterTaps: true } },
  );

  if (!props.children) return null;

  return (
    <mesh position={position} {...bind()}>
      {props.children}
    </mesh>
  );
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!