PointerDragBehavior - dragAxis - inconstant behavior with dragAxis other than Axis

I noticed a weird behavior on the pointerDragBehavior. When using dragAxis values other than Axis X, Y, Z the mouse cursor is not ‘really’ following the attachedNode

I made a playground with a green sphere to render the current dragPlanePoint of the behavior.

I found a way of computing it, in this playground the blue sphere is following the line and the mouse cursor, the gray sphere is the position from the actual behavior https://playground.babylonjs.com/#YEZPVT#2536

We have to store the initial drag position

let dragStartPosition = BABYLON.Vector3.Zero()
pointerDragBehavior.onDragStartObservable.add((event)=>{
      dragStartPosition = event.dragPlanePoint
  })

Then we can use it to compute the right position

pointerDragBehavior.onDragObservable.add((event)=>{
    const dragAxis = pointerDragBehavior.options.dragAxis
    const dragPlanePoint = event.dragPlanePoint.subtract(dragStartPosition)
    const scale = BABYLON.Vector3.Dot(dragPlanePoint, dragAxis) / BABYLON.Vector3.Dot(dragAxis, dragAxis) 
    sphereDragPlanePoint.position = dragStartPosition.add(dragAxis.scale(scale))
})

Would you like me to try to make a PR ?

1 Like

That sure looks wrong! If you could, A PR would be much appreciated.
Let’s also cc @amoebachant on this.

1 Like

Thanks friend :slight_smile:

1 Like