Drag&drop x y in X Z

when messing around in the drag&drop sample https://www.babylonjs-playground.com/#UZ23UH#0
i tried undersytanding how tthe X Y system worked as this is a great sample to start with for what i had in mind but i could’t figer out how i could chance the Y in a Z so indead of distance height?
i tried chancing the var pickinfo = scene.pick(scene.pointerX, scene.pointerY, into
var pickinfo = scene.pick(scene.pointerX, scene.pointerZ, but somehow that didn’t work and got confused about it can somebody explain this please? thank you

You might also be able to rely on our provided behaviors: Use Mesh Behaviors (eg. dragging) - Babylon.js Documentation

https://www.babylonjs-playground.com/#9UFEBE

In this mode you could set the drag plane to your prefered axis

sorry but the method you provided is competly diffrent then the sample i provided and the method is thus also diffrent could you please explain how the x y z work in the sample link i provided?

scene pointers are only in 2d as the screen is flat. it then needs to be converted to your drag plane by for instance finding the collision point between the screen coordinates converted to world space propagated along the camera direction until it collides with the drag plane.

2d is fine by me but right now its left/right and forward/backwards i wish to replace the last one with up/down would that be poseble with my current state?

cc @trevordev who did the drag drop support in Babylon as I bet he might be able to help here.

Hey, scene.pointerX, scene.pointerY are the x and y position of your screen, which is 2D so z doesn’t exist. internally in scene.pick method it users the camera’s setup to create a 3D ray starting from the camera’s position through the cameras viewport using the scene.pointerX, scene.pointerY position on it. that is done with scene.createPickingRay

image

if you want to get the z distance when picking you need to see where the 3D ray intersects with a flat plane in the scene which will be found in the pickInfo.pickedPoint which corresponds the the 3D point the ray hit in the scene.

1 Like