How to drag more than one object multiple times :)

Well here is another question from the newbie :smiley: I actually am experimenting with a scene of 3 meshes: a sphere and 2 cones. I want to drag the objects with my mouse and put them in the scene wherever i want.

So i did this:

 sphere.isPickable = true;
cone.isPickable = true;
cone2.isPickable = true;

var actualmesh;

 scene.onPointerDown = function (evt, pickResult) {
    // We try to pick an object
    if (pickResult.hit && pickResult.pickedMesh.isPickable==true) {
      actualmesh = pickResult.pickedMesh;
      actualmesh.addBehavior(pointerDragBehavior);
    }
};

 scene.onPointerUp = function (evt, pickResult) {
     actualmesh.addBehavior(pointerDragBehavior.release);
 }

However if I do so, I can move the objects, but only the latest one picked keeps moveable. To me it seems that I did not get the point with poitnerDragBehaviour clearly and how to attach my meshes properly to it. Maybe someone can lend a helping hand and advice how to perform this properly :slight_smile:

thanks a lot :slight_smile: I found the example before but hoped there would be an easier way by using pointerDragBehavior :))

1 Like

well I analyzed the example and was able to implement it in my scene. I can now handle pickable and not pickable meshes as well. thanks a lot. #solved

Since the solution reply was deleted, Iā€™m just uploading it here in order to be archived.

Solution: https://www.babylonjs-playground.com/#UZ23UH#0