Page 1 of 1

Understanding the tile co-ordinates

Posted: Thu Sep 12, 2013 11:04 am
by robaldred
I'm having some trouble understanding the tile co-ordinates. Specifically the overTiles() method, it seems to return points that are confusing me.
I want to be able to find out where my entities are and how many tiles away they are from other entities.

1st test:
Dog at x:0,y:0 overTiles() reports x:0,y:0, happy days.
Distance returns 0.
Screen Shot 2013-09-12 at 11.21.51.png
2nd test:
I've moved the dog to tile x:2,y:0, however overTiles() reports it's on x:1,y:-1 :?
Distance returns 1.4142135623730951
Screen Shot 2013-09-12 at 11.21.17.png
3rd test:
I've moved the dog to tile x:0,y:2, however overTiles() reports it's on x:2,y:2 :?
Distance returns 2.8284271247461903
Screen Shot 2013-09-12 at 11.21.31.png
4th test:
I've moved the dog to tile x:9,y:9 however overTiles() reports it's on x:14,y:5
Distance returns 14.866068747318506
Image

Re: Understanding the tile co-ordinates

Posted: Thu Sep 12, 2013 11:13 am
by coolbloke1324
Hey answering from my phone so will be short at moment but points are 2d unless told otherwise. Check iso example quests in character container class to see how to get iso coordinates from 2d point. It is very easy has built in method in igepoint.

Rob

Re: Understanding the tile co-ordinates

Posted: Thu Sep 12, 2013 11:32 am
by robaldred
Ahh magic!

Code: Select all

entity._parent.pointToTile(entity._translate.toIso())
Thanks, I thought I was going crazy :)

Re: Understanding the tile co-ordinates

Posted: Thu Sep 12, 2013 11:48 am
by robaldred
Hi again, so the tile positions are good!
However the distance method that's added to Math seems to get less accurate the further the distance.

eg.
Sheep is on 0,0

.1
I've moved the dog so it's on tile x:5 y:5
with diagonal pathing, the dog is 5 tiles away from the sheep.
However, distance calculation says 7

Code: Select all

Math.distance(0,0,5,5) # => 7.0710678118654755
.2
Moving dog to 9,9 distance returns 12

Code: Select all

Math.distance(0,0,9,9) # => 12.727922061357855
It's good enough for what I need, I need to check for entities on neighbouring tiles.

Re: Understanding the tile co-ordinates

Posted: Thu Sep 12, 2013 12:32 pm
by coolbloke1324
Distance is calculated via pythagorean theorem and your results are correct. Remember the values are 2d coordinates not projected to isometric. The distance still works though. It is the hypotenuse line from point to point.

Re: Understanding the tile co-ordinates

Posted: Thu Sep 12, 2013 1:20 pm
by robaldred
Do you know what maths would be to reliably calculate the distance in tiles between two iso tile points?

Re: Understanding the tile co-ordinates

Posted: Thu Sep 12, 2013 1:28 pm
by coolbloke1324
robaldred wrote:Do you know what maths would be to reliably calculate the distance in tiles between two iso tile points?
X distance = startx - endx
Y distance = starty - endy

Now you know how many tiles in each vector the start position is away from the end position.

Re: Understanding the tile co-ordinates

Posted: Thu Sep 12, 2013 1:38 pm
by robaldred
Thanks for your help Rob

Re: Understanding the tile co-ordinates

Posted: Wed Sep 25, 2013 3:47 am
by zaquanishak
Hi,
im having the same problem about the overTiles() method. Currently im using the overTiles method in my characterContainer class update method to compare which tile the character is step on. The code as below.

Code: Select all

 var tiles = this.overTiles(), playerReachDoor = false;

                if((tiles[0].x === 1) && (tiles[0].y === 1)){
                playerReachDoor = true;
                if(playerReachDoor === true){
                    ige.network.send('goToDoor' , {id: this.id() , map:2});
                    playerReachDoor = false;
                }

                this.break;
            }
but the location of the tiles is not the same similar problem as robaldred. So i would like to as how to i use

Code: Select all

entity._parent.pointToTile(entity._translate.toIso())
to convert the overTiles method to be isometric?

Please advise.

Regards,
Zachz

Re: Understanding the tile co-ordinates

Posted: Fri Sep 27, 2013 9:37 pm
by coolbloke1324
Hey ya,

I believe this has now been answered in a different question thread you made.