I want to make a drag system in which when the user clicks on a geometry a div appears and when the div is dragged the object drags with it. So far I have made the div to drag the object with it here’s the CodeSandbox if anyone is interested:
The only issue I am facing now is that the dragging gets inverted if the camera is rotated, if anyone can help me regarding this I’ll be very grateful.
You can use the raycaster on the ground plane to get the click position in world space, and use that to compute the movement delta, by subtracting the current hit.point from the previous hit.point, and adding that to your object.
Trying to translate the div position into a worldspace drag amount is possible, but it’s unnecesarily difficult when you can just use the raycaster.
The issue is that I know how to use the raycaster to get the intersection position but in the code of useDrag the event is returning the functions and properties of the div rather than that of the boxGeometry. If the event returns the function and properties of the boxGeometry I can easily utilise the .ray property to calculate the intersection and set the new position.