Follow mouse/pointer with smooth acceleration/declaration

I want to make a sprite or a camera that following mouse smoothly, like this game http://preview.codecanyon.net/item/sniper-mission-html5-shooter-game/full_screen_preview/17345389

I don’t have any idea how to do this with Phaser 3

There are different ways to do it, I do it like this (removed some to simplify it, I think it works but have not tested) when making an enemy chase the player with smoothed out movement. This is in the update method of the sprite.

let wayPoint = this.player.getCenter(); //Player, change to for example scene.input.activePointer or something
let ownPos = this.getCenter(); //Enemy, the sprite or camera 

let direction = wayPoint.subtract(ownPos).normalize(); //.scale(this.speed) I scale with a configurable this.speed to make enemy move faster/slower depending on situation.
let lerpedDirection = direction.lerp(this.body.velocity, 0.2); // Set 0.2 to 0.99 to get very smooth movement

this.setVelocity(lerpedDirection.x, lerpedDirection.y);

Thanks for your reply!

But i have a more simplest solution, but i don’t know is it good to use or not.

var aim = this.physics.add.sprite(300,50,'p');
	this.input.on('pointermove', function(pointer) {
	    this.tweens.add({
	    	targets: aim,
	    	x: pointer.x,
	    	y: pointer.y,
	    	duration: 1000,
	    	ease: 'Sine.easeOut',
	    }, this);
	}, this);

If it works, it works!

Possibly using a tween can create some unwanted behavior with physics and interaction between objects. If it behaves as you like, it is not an issue.

Perhaps there is an overhead when adding many tweens rapidly, could be an issue, but if performance is fine then again, no problem. Could tweak and add a check so that a new tween is only added when pointer moved a certain distance.

If you do not move the pointer then the tweened object will stop after 1 sec I suppose? would need a fix for that. I think a callback on tween end that checks distance to pointer and tweens again is simple enough.

I forget to change it’s physics to sprite.

I also think it’s bad by adding tween rapidly.

I delayed this project for a while.

Anyway, thanks for your help!