Limit draggable distance, or speed?

I just have to say I love Phaser. After trying Unity and Godot I realized I wanted a simpler experience that also is a great excuse for me to relearn JavaScript (it’s been 20 years since I coded it in college).

As I’m learning js and playing with Phaser 3 and Matter.js, I’m wondering if there’s a way to limit the draggable distance of an object, or perhaps make the distance it moves a function of the distance the cursor travels (object moves 1/10 the distance cursor moves).

I couldn’t find any examples here https://helpcenter.phasereditor2d.com/ but I might be missing something, or might need some tricky math down the road. I don’t need any solutions, but some functions to research and play around with would be welcome.

this.input.on('pointermove', function (pointer) {
    // get pointer x/y difference, update object 1/10th of vector,
    // optionally within limits
}, this);

Using collision and dragging is a problem for Matter, see here.
See here for a lot of Matter examples.

1 Like

That’s great! I wasn’t even aware of Planck.js either, thanks for the direction.

I was so worried the core mechanic of my game wouldn’t be feasible, but now at least I can prototype it to see if it’s even fun.