# getTileAtWorldXY() selects wrong tile on hex maps from Tiled

**URL:** <https://phaser.discourse.group/t/gettileatworldxy-selects-wrong-tile-on-hex-maps-from-tiled/11643>\
**Category:** Phaser 3\
**Created:** [May 6, 2022, 12:19am UTC](https://phaser.discourse.group/t/gettileatworldxy-selects-wrong-tile-on-hex-maps-from-tiled/11643 "2022-05-06T00:19:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![druerridge](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/druerridge/32/6487_2.png) [@druerridge](https://phaser.discourse.group/u/druerridge)\
**Post date:** [May 6, 2022, 12:19am UTC](https://phaser.discourse.group/t/gettileatworldxy-selects-wrong-tile-on-hex-maps-from-tiled/11643/1 "2022-05-06T00:19:23Z")

</div>

Hey folks,

Been looking at this for hours and can’t figure out if I’m doing something wrong. I made a minimal example to reproduce - it adds a tint to the hex currently under the mouse, and loads the hexagon tile map example that is packaged with the Tiled map editor.

As you can see in the image, the “selected” tile is offset considerably from the point of the mouse.

Here’s a repo for the minimal repro

> **[GitHub - druerridge/hexfail: Cannot get hex grids from Tiled to work in Phaser3](https://github.com/druerridge/hexfail)**
>
> Cannot get hex grids from Tiled to work in Phaser3 - GitHub - druerridge/hexfail: Cannot get hex grids from Tiled to work in Phaser3

All the code is basically in this file:

> <https://github.com/druerridge/hexfail/blob/main/game.js>

 ![hex-fail](https://global.discourse-cdn.com/free1/uploads/phaser1/original/2X/c/cc02c7018d75832a80e3da61e62d07ef42d04fcf.jpeg)

---

<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:** [May 6, 2022, 4:24pm UTC](https://phaser.discourse.group/t/gettileatworldxy-selects-wrong-tile-on-hex-maps-from-tiled/11643/2 "2022-05-06T16:24:05Z")

</div>

👋

> <https://github.com/photonstorm/phaser/issues/5781>
>
> \## Version
> 3.55.2
> \## Description
> 
> When trying to grab a tile under the mouse… pointer, there is some offset grabbing the wrong tile.
> 
> 
> \## Example Test Code
> \`\`\`
> var config = {
> type: Phaser.WEBGL,
> width: 800,
> height: 600,
> backgroundColor: '#2d2d2d',
> parent: 'phaser-example',
> pixelArt: true,
> scene: {
> preload: preload,
> create: create,
> update: update
> }
> };
> 
> var controls;
> 
> var game = new Phaser.Game(config);
> 
> var layer1;
> var cursorTile;
> 
> function preload ()
> {
> this.load.image('tiles', 'assets/tilemaps/iso/iso-64x64-outside.png');
> this.load.image('tiles2', 'assets/tilemaps/iso/iso-64x64-building.png');
> this.load.tilemapTiledJSON('map', 'assets/tilemaps/iso/isorpg.json');
> }
> 
> function create ()
> {
> var map = this.add.tilemap('map');
> 
> console.log(map);
> 
> var tileset1 = map.addTilesetImage('iso-64x64-outside', 'tiles');
> var tileset2 = map.addTilesetImage('iso-64x64-building', 'tiles2');
> 
> this.layer1 = map.createLayer('Tile Layer 1', \[tileset1, tileset2 \]);
> var layer2 = map.createLayer('Tile Layer 2', \[tileset1, tileset2 \]);
> var layer3 = map.createLayer('Tile Layer 3', \[tileset1, tileset2 \]);
> var layer4 = map.createLayer('Tile Layer 4', \[tileset1, tileset2 \]);
> var layer5 = map.createLayer('Tile Layer 5', \[tileset1, tileset2 \]);
> 
> var cursors = this.input.keyboard.createCursorKeys();
> 
> this.cameras.main.setZoom(2);
> 
> var controlConfig = {
> camera: this.cameras.main,
> left: cursors.left,
> right: cursors.right,
> up: cursors.up,
> down: cursors.down,
> acceleration: 0.04,
> drag: 0.0005,
> maxSpeed: 0.7
> };
> 
> controls = new Phaser.Cameras.Controls.SmoothedKeyControl(controlConfig);
> }
> 
> function update (time, delta)
> {
> controls.update(delta);
> if (this.cursorTile != null) {
> this.cursorTile.setVisible(true);
> }
> 
> this.game.input.mousePointer.updateWorldPoint(this.cameras.main);
> const foundTile = this.layer1.getTileAtWorldXY(this.game.input.mousePointer.worldX, this.game.input.mousePointer.worldY, false, this.cameras.main);
> 
> 
> if (foundTile != null) {
> this.cursorTile = foundTile;
> }
> this.cursorTile.setVisible(false);
> }
> 
> \`\`\`

---

<div class="post-metadata">

**Author:** ![druerridge](https://yyz2.discourse-cdn.com/free1/user_avatar/phaser.discourse.group/druerridge/32/6487_2.png) [@druerridge](https://phaser.discourse.group/u/druerridge)\
**Post date:** [May 13, 2022, 5:39pm UTC](https://phaser.discourse.group/t/gettileatworldxy-selects-wrong-tile-on-hex-maps-from-tiled/11643/3 "2022-05-13T17:39:35Z")

</div>

I believe the shape it’s responding to is a square as well, instead of a hexagon. This, in combination with a couple other things (below) make hexagon tilemaps prettymuch unusable ☹

- getTileAtWorldX() always returns 0
- once scaled, getTileAtWorldXY() returns even crazier answers
