# Mouse pointer coordinates don't update

**URL:** <https://phaser.discourse.group/t/mouse-pointer-coordinates-dont-update/1805>\
**Category:** Phaser 3\
**Created:** [March 24, 2019, 9:05am UTC](https://phaser.discourse.group/t/mouse-pointer-coordinates-dont-update/1805 "2019-03-24T09:05:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Goliath86](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/goliath86/32/978_2.png) [@Goliath86](https://phaser.discourse.group/u/Goliath86)\
**Post date:** [March 24, 2019, 9:05am UTC](https://phaser.discourse.group/t/mouse-pointer-coordinates-dont-update/1805/1 "2019-03-24T09:05:16Z")

</div>

Hi all,  
I’m facing a problem relative to mouse pointer: the worldX and worldY coordinates don’t update if I don’t move the mouse and only move the camera. The game I’m developing is a top-down shooter and the camera follow the player that is always at the center of the screen. As said before, if I only move the camera but not the mouse, the worldX and worldY coordinates of the mouse pointer don’t change but if I _only click_ a button of the mouse, the coordinates will update correctly. I suspect that the worldX and worldY coordinates are updated only on mouse event (move and click) and not during every frame. Am I correct? How can I get the mouse coordinates relative to world even if the mouse is not moving (or clicking) but only the camera?

Thanks in advance

---

<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:** [March 24, 2019, 4:39pm UTC](https://phaser.discourse.group/t/mouse-pointer-coordinates-dont-update/1805/2 "2019-03-24T16:39:08Z")

</div>

[https://labs.phaser.io/view.html?src=src/input\mouse\poll%20always.js](https://labs.phaser.io/view.html?src=src/input%5Cmouse%5Cpoll%20always.js)

---

<div class="post-metadata">

**Author:** ![allard](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/allard/32/3260_2.png) [@allard](https://phaser.discourse.group/u/allard)\
**Post date:** [April 26, 2020, 3:46pm UTC](https://phaser.discourse.group/t/mouse-pointer-coordinates-dont-update/1805/3 "2020-04-26T15:46:45Z")

</div>

I had the same issue but fixed it with another solution.

My `update()` was:

```javascript
this.rotation = Phaser.Math.Angle.Between(this.x, this.y, this.scene.input.mousePointer.worldX, this.scene.input.mousePointer.worldY)

```

The worldX and worldY were not updated on camera movement unless I moved my pointer. I was able to fix it by using the regular x/y and combining it with the camera x/y.

```javascript
const crosshairX = this.scene.input.mousePointer.x + this.scene.cameras.main.worldView.x
const crosshairY = this.scene.input.mousePointer.y + this.scene.cameras.main.worldView.y
this.rotation = Phaser.Math.Angle.Between(this.x, this.y, crosshairX, crosshairY)

```

I don’t know if it is better then `setPollAlways` though…

---

<div class="post-metadata">

**Author:** ![TomYeoman](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/tomyeoman/32/4572_2.png) [@TomYeoman](https://phaser.discourse.group/u/TomYeoman)\
**Post date:** [January 6, 2022, 8:47pm UTC](https://phaser.discourse.group/t/mouse-pointer-coordinates-dont-update/1805/4 "2022-01-06T20:47:20Z")

</div>

For anyone stumbling on this `setPollAlways` doesn’t work, here’s how to solve this -

```javascript
getMouseCoords() {
    // Takes a Camera and updates this Pointer's worldX and worldY values so they are the result of a translation through the given Camera.
    this.scene.input.activePointer.updateWorldPoint(this.scene.cameras.main);
    const pointer = this.scene.input.activePointer
    return {
      mouseX: pointer.worldX,
      mouseY: pointer.worldY,
    }
  }

```

Found this issue which helped - [setPollAlways() does nothing. InputManager only updates on DOM event callback. · Issue #4405 · photonstorm/phaser · GitHub](https://github.com/photonstorm/phaser/issues/4405)
