javascript - mouse position to isometric tile including height -


Trouble translating the position of the mouse in place of tiles in my grid. When this is all flat, then math looks like this:

  this.position.x = Math.flur (((pos.y - 240) / 24) + ((pos.x - 320) / 48)); This.position.y = Math.flur (((pos.y - 240) / 24) - ((pos.x - 320) / 48));  

Where pos.x and pos.y are the positions of the mouse, 240 and 320 are offset, in the 24 and 48 tile size position there are grid coordinates of the tile that I am hovering above It works great on a flat surface

Enter image details here < / P>

Now I am adding height, which does not take into consideration mathematics.

Enter image details here

This grid 2D grid It is noise, it's being translated into height and tile type height is actually just an adjustment for the tile's 'Y' position, so it is possible that two tiles can be dragged to one place.

I do not know how to decide on which tile I'm slipping.

Edit:

Some progress made ... Before, I rely on the mouseover event to calculate the grid position. I have changed it to be calculated only in the draw loop, and check whether the coordination is within the boundaries of the tiles currently created or not. Although some overhead builds, not sure if I'm super happy with it but I confirm that it works.


Comments

Popular posts from this blog

eclipse plugin - Run java code error: Workspace is closed -

ios - How do I use CFArrayRef in Swift? -

scala - Play Framework - how to bind form to a session field -