Jump to content

Arcade Physics moveToPointer issue


Recommended Posts

Hey all,


Brand new here and I am having an issue creating a dragging object effect that lags behind the mouse. I have tried programming a draggable object manually but that didn't go so well so I looked into the moveToPointer function under arcade physics. The issue is, it seems to have a bug where the object you are moving bounces back and forth when extremely close to the pointer in question. See this example here:



I assume this is occurring because the object moves past the pointer by a few pixels in one update and then in the very next its velocity gets flipped to move it back towards the pointer. Does anyone have any recommendations on how to prevent/fix this?

Link to comment
Share on other sites

I tried that and it didn't work very well. I had the same "bouncing" as seen in the example above. Instead I just manually check to see if the position of the object is within a certain rectangle by doing a custom if statement. This worked perfectly. Thanks for the reply though! Here is my code for the check:


if (this.input.activePointer.x > sprite.x - 10 && this.input.activePointer.x sprite.x + 10
&& this.input.activePointer.y sprite.y - 10 && this.input.activePointer.y sprite.y + 10) {
sprite.body.velocity.setTo(0, 0);
} else if(this.input.activePointer.x sprite.x - 150 && this.input.activePointer.x sprite.x + 150

&& this.input.activePointer.y sprite.y - 150 && this.input.activePointer.y sprite.y + 150) {

//For an Easing affect
speed * (this.physics.arcade.distanceToPointer(sprite) / 100));

} else {
this.physics.arcade.moveToPointer(sprite, speed);

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...