Check drag direction on plane

Hello everyone,

I try since hours to check in which direction an object is dragged. My idea was to read the delta values on drag. That should work but I receive a lot of delta values equal 0 wherefore my function don’t know if it is going up or down.

https://playground.babylonjs.com/#QJRA8R#2

Why are there these 0 deltas and how to check the direction instead?

Best

Maybe @Cedric will know what’s going on.

event.delta is close to zero when the mouse delta position is not big enough.
This is not an issue when you add the delta to an object position but it can be an issue when you analyse the delta for something else.

The only I see is to use a threshold value and discard the event when you don’t get enough delta. Also, use a threshold to filter the axis value.

I changed your PG to illustrate:

Apply flat shaded mesh cause error | Babylon.js Playground

Another way to filter is to get the higher absolute value of each component of the delta. You’ll get the most representative axis.
Or, accumulate the event.delta into a Vector3 and once its length reaches a threshold, get its tendency and set the accumulation back to (0,0,0).

I like your threshold solution. It works perfectly. Thanks! :slight_smile:

1 Like