How do I make the player turn in the mouse direction?

Hi everyone I am learning Phaser and I wanted to add an extra piece to my knowledge.
I’m doing a little top view shooter game.

I added the background, the player and the controls to make it move inside the canva.

My idea was to make the player rotate based on the movement of the mouse.
This will be used for aiming and shooting. (I will add the shot at the click of the mouse)

var config = {
    type: Phaser.AUTO,
    width: 800,
    height: 600,
    physics: {
        default: 'arcade',
        arcade: {
            debug: true
        }
    },
    scene: {
        preload: preload,
        create: create,
        update: update
    }
};

var game = new Phaser.Game(config);
var player;

function preload() {
    //load background asset
    this.load.image('background', 'assets/background.png')
    this.load.spritesheet('player', 'assets/player.png', {
        frameWidth: 48,
        frameHeight: 48
    });
}

function create() {
    //add background
    this.add.image(400, 300, 'background');
    player = this.physics.add.sprite(400, 300, 'player');
    player.setCollideWorldBounds(true);

    cursors = this.input.keyboard.createCursorKeys();
}

function update() {

    if (cursors.left.isDown) {
        player.setVelocityX(-200);
    } else if (cursors.right.isDown) {
        player.setVelocityX(200);
    } else {
        player.setVelocityX(0);
    }

    if (cursors.up.isDown) {
        player.setVelocityY(-200);
    } else if (cursors.down.isDown) {
        player.setVelocityY(200);
    } else {
        player.setVelocityY(0);
    }
}
1 Like

Something like this ,but I can’t get this example working

1 Like

Thank you!!! It works