PointerDragBehavior to drag in X, Y or Z

Hello there, I’m testing PointerDragBehavior, and I can achieve to drag my meshes for example on the X axis using

const pointerDragBehavior1 = new BABYLON.PointerDragBehavior({ dragAxis: new BABYLON.Vector3(1, 0, 0) });

What I would like to do is to change the behaviour of the the PointerDragBehavior, based on the mouse movement I’m doing. I would like to to drag my mesh in the X, Y or Z axis based on the vector movement of the mouse, so I can decide very easily how to move my mesh. If I mouse my mouse from bottom to up, for example, I would like to move the mesh in the Y axis, an so forth. How can I achieve this?

Thank you in advance for your help


Adding @Cedric

Something like a PlaneDragGizmo maybe ?

1 Like

Thank you, perfect! But if I would like to constraint the movement in one of the 3 axis, alternatively, should I write some code myself in order to choose the right axis and the apply the correct PointerDragBehavior to the mesh?

Thank you


Yes, you have to constrain the delta. something like this:

constraint axis move | Babylon.js Playground (babylonjs.com)


Thank you again!

1 Like