Increase efficiency of Collision

I have implemented collision with DragControl but I am confused with its unusual behaviour.

So if the geometry is being dragged slowly and then collides with the wall the precision of its collision is too good. But if the same geometry is being dragged way too fast it leaves a gap between the wall and the object itself. Here’s the sandbox for better visuals:

https://codesandbox.io/p/sandbox/dragging-html-5g6nvk

Also if anyone that is a professional in R3F and can guide me why the same code works with DragControls by three.js but not with DragControls provided by drei or useDrag I’ll be grateful, I have been trying to make this work with useDrag and DragControls but it doesnt seem to work hence I have to use useEffect for the drag to take effect.

If anyone needs I can also link the same collision made in vanilla three.js.

Break distance of dragging to parts to check all parts for collision.

1 Like

Hmm that’s a nice idea, can you give me an example regarding this I am kinda bad with this stuff. :smile:

Change this code:

dragged_position=new THREE.Vector(50,20,40);
direction=new THREE.Vector().subVectors(dragged_position,mesh.position).normalize();
dragged_distance=mesh.position.distanceTo(dragged_position);
small_distance=0.1;
while(dragged_distance>0){
mesh.position.add(direction.x*small_distance,direction.y*small_distance,direction.z*small_distance);
if(collision()){ break; }
dragged_distance-=small_distance;
}
1 Like

Should I make this using useDrag since the variable dragged_position contains the position the object should drag to if I am not wrong.

Thanks for the help though you really helped me with that one.

does this help? https://codesandbox.io/p/sandbox/drag-n-drop-with-physics-and-collisions-9pjzm6 it would leave collision to the physics engine.

Thanks for replying, I did check this example when I was starting to work on this example but you see that I need to move the objects using DragControls or using a div, I was unable to make it move using the div so instead I ended up using DragControls.

If this was working with DragControls this would have saved me soo much time.

I dont know english good and how work drag function. You need add code to drag code. And then move object in that place of code insert dragged_position which is mean drage position. But object move in “while” code with small steps