Sort object by drag

Good evening everyone,

I am working on playground that should allow the user to change the order of objects along the x-axis by dragging it. I am quite happy with the current state but I am not sure how to solve the problem mentioned below.


1 on keyboard: adds module_1
2 on keyboard: adds module_2
0 on keyboard: removes last module
drag: ability to move object to another position

If you drag an object and move the mouse just up and down the box moves left and right. I want the object to be sticking to the mouse. So it should only move left or right if I move my mouse left or right.

I would love to get some other thoughts about that.


1 Like

Maybe @Cedric would have a tip to disable the mouse up down ?

I changed the plane orientation used for picking to make it perpendicular. I also offseted it a bit to not break the rendering.

Babylon.js Playground

I think it works a bit better and there is no mouse Y only movement.



Way better. Thank you very much :slight_smile:

Is there still something we can do to improve the behavior du to the camera perspective? If you are on nearly 0 or 180 degrees it would be nice to move the object with up and down again. I am not sure how to describe it:

Object is moved only on X (line 155), you can also move it on Y axis depending on the camera alpha angle.

1 Like