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

**URL:** https://phaser.discourse.group/t/how-do-i-make-the-player-turn-in-the-mouse-direction/8727
**Category:** Phaser 3
**Created:** [January 25, 2021, 2:09pm UTC](https://phaser.discourse.group/t/how-do-i-make-the-player-turn-in-the-mouse-direction/8727 "2021-01-25T14:09:41Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![adcoding](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/adcoding/32/3052_2.png) [@adcoding](https://phaser.discourse.group/u/adcoding)
#### Post date: [January 25, 2021, 2:09pm UTC](https://phaser.discourse.group/t/how-do-i-make-the-player-turn-in-the-mouse-direction/8727/1 "2021-01-25T14:09:41Z")

</div>

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);
    }
}
```

---

<div class="post-metadata">

### Author: ![adcoding](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/adcoding/32/3052_2.png) [@adcoding](https://phaser.discourse.group/u/adcoding)
#### Post date: [January 25, 2021, 3:01pm UTC](https://phaser.discourse.group/t/how-do-i-make-the-player-turn-in-the-mouse-direction/8727/2 "2021-01-25T15:01:07Z")

</div>

Something like [this](https://phaser.io/examples/v2/arcade-physics/angle-to-pointer) ,but I can’t get this example working

---

<div class="post-metadata">

### Author: ![samme](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/samme/32/5275_2.png) [@samme](https://phaser.discourse.group/u/samme)
#### Post date: [January 25, 2021, 4:52pm UTC](https://phaser.discourse.group/t/how-do-i-make-the-player-turn-in-the-mouse-direction/8727/3 "2021-01-25T16:52:06Z")

</div>

https://codepen.io/samme/embed/preview/gOpPLLx?height=300&slug-hash=gOpPLLx&default-tabs=js,result&host=https://codepen.io

---

<div class="post-metadata">

### Author: ![adcoding](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/adcoding/32/3052_2.png) [@adcoding](https://phaser.discourse.group/u/adcoding)
#### Post date: [January 27, 2021, 12:00pm UTC](https://phaser.discourse.group/t/how-do-i-make-the-player-turn-in-the-mouse-direction/8727/4 "2021-01-27T12:00:55Z")

</div>

Thank you!!! It works
