Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda