chadweigle Posted July 9, 2015 Share Posted July 9, 2015 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:http://phaser.io/examples/v2/input/follow-mouse 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 More sharing options...
rich Posted July 10, 2015 Share Posted July 10, 2015 Use Pointer.circle and detect if the object is within it or intersecting with it and don't do the move if it is. Link to comment Share on other sites More sharing options...
chadweigle Posted July 10, 2015 Author Share Posted July 10, 2015 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 affectthis.physics.arcade.moveToPointer(sprite,speed * (this.physics.arcade.distanceToPointer(sprite) / 100));} else {this.physics.arcade.moveToPointer(sprite, speed);} Link to comment Share on other sites More sharing options...
Recommended Posts