Arcade Physics - How to enable Collision when dragging an Object?

Hi,
I just started learning Phaser 3 and I am trying to drag a ball object with the mouse to hit another ball using the velocity of the mouse. But when I drag the first Ball, the physics body’s velocity doesn’t change, and the second ball doesn’t move.
If anyone can help, I would really appreciate it.
Thank you all.

This the code I am using:

function create ()
{
var ball1 = this.physics.add.image(100, 240, ‘ball’);
var ball2 = this.physics.add.image(700, 240, ‘ball’);

ball1.setCircle(46);
ball2.setCircle(46);

ball1.setCollideWorldBounds(true);
ball2.setCollideWorldBounds(true);

ball1.setBounce(1);
ball2.setBounce(1);

this.input.setDraggable(ball1.setInteractive());

this.input.on('dragstart', function (pointer, obj)
{
    obj.body.moves = true;
});

this.input.on('drag', function (pointer, obj, dragX, dragY)
{
    obj.setPosition(dragX, dragY);
});

this.input.on('dragend', function (pointer, obj)
{
    obj.body.moves = true;
});
this.physics.add.collider(ball1, ball2);

}

Hi,
Thanks for the reply, but I read that post and it doesn’t have the solution.

There isn’t a simple solution. I think you have two options:

  • Apply the scaled Pointer velocity to the dragged object’s Body, possible with smoothing. This is reliable but it’s not the same kind of motion as input dragging.
  • Do your own collision detection and separation in the drag callback.