Snap to grid on drag in Phaser 3

Hello,
I’m trying to snap to grid whilst dragging - much in the same way as atari1 in this example:
https://phaser.io/examples/v2/input/snap-on-drag

Unfortunately this doesn’t seem to work in Phaser 3 - is there any built in functionality for snapping whilst dragging? If not, what is the best way to do this?

this.input.on('drag', function (pointer, gameObject, dragX, dragY) {
  gameObject.x = Phaser.Math.Snap.To(dragX, 32);
  gameObject.y = Phaser.Math.Snap.To(dragY, 32);
});
3 Likes

Thank you, this worked perfectly.