How to create a mesh and drag it simultaneously

Hi everyone,

I want to do following operation:

  1. pointer down on a mesh, and hold the pointer;
  2. drag pointer, then create another mesh on previous mesh’s position;
  3. keep dragging, move new created mesh.

in other words: pointer down on mesh A and hold → drag start (create mesh B) → drag (move B with pointer on plan perpendicular to camera norm) → pointer (release it)

I have tried with scene.onPointerObservable and PointerDragBehavior, the code is either ugly or non-work. How can I do that?

Hello @Roy-Kid and welcome back to the forum

you can do a combination of PointerDragBehavior and ActionManager to achieve the wanted behaviour.

here’s a quick playground I made based on your description, hope this helps:


Miracle!! Thanks a lot for your help! It’s so difficult to implement mouse operation by using those simple events. I will have a try tonight!

1 Like

Hi! Thanks for your help!

I have tried your solution, and I found a problem. I want sphere to move along the plane facing the camera. According to doc, I just need to leave PointerDragBehavior() blank, or I can use to define a plane parallel to the camera. But the sphere is very weird. Could you help me find out why?

hum. it seems like attaching the dragBehavior when it’s already dragging made the sphere moves not according to the right dragDistance.

what about onDragStart you clone the mesh and keep dragging the original mesh instead ? looks like it works better that way.

That’s much more better! I can even create a new mesh instead of cloning it. I’ll try to integrate it into my code! Thanks!

1 Like