Gizmo/Mesh movement limitation

Hello everyone,
is it possible to make gizmo (eq. Yplane) move only inside 2d square? To add something like

if(position.x < min.x || position.x > max.x) {
return false;
if(position.z < min.z || position.z > max.z) {
return false;

inside yPlaneGizmo.dragBehavior.onDragObservable

here’s the playground for example:

pinging @Cedric

You can check the attached mesh and constrain its position. If you have no mesh, you can add a transient transform. Once it’s done, it’s just a matter of setting the position in onDragObservable. Like this:

constrained mesh gizmo | Babylon.js Playground

1 Like

as always, thank for the fast reply @Cedric :smiley: what about if the plane is rotated? I think there’s need to be a method that takes position of mesh and rotation of plane? So it could calculate eq. max position of x with the given x, z?

You can multiply the position by the invert of the plane world matrix. then do the clipping and multiply back the result by the plane world matrix.

Works with position/scale/orientation.