Hi guys, I have a problem i cant solve easily it seems.
I did a Pacman grid map using Tiled software. i copied the matrix from the json it produces and i have created a class for this map, it holds the public static in[,] matrix of 28 col X 36 rows representing the map.
Then i did a TileCreator that spawns every 1X1 tile.
void spawnTiles(){
for (int Y = 0; Y <28; Y++) {
for (int X = 0; X < 36; X++) {
if (map[X,Y] == 2) {
GameObject go = Instantiate(VioletCube, new Vector2(Y * 10,-X*10), Quaternion.Euler(-90,0,0));
go.transform.parent = this.transform;
}
if (map[X,Y] == 1){ GameObject go=Instantiate(blackCube, new Vector2(Y * 10,- X * 10), Quaternion.Euler(-90, 0, 0));
go.transform.parent = this.transform;
}
}
}
}
IF i want to know if the next tile is valid i have to do this, please not the X,Y inverted.
csharp** ** public bool nextTileIsValid (Vector3 dir){ if (dir.x == 1)return Mapa.map [mYPos, mXPos+1] == 1; if (dir.x == -1)return Mapa.map [mYPos, mXPos-1] == 1; if (dir.z == 1)return Mapa.map [mYPos-1, mXPos] == 1; if (dir.z == -1)return Mapa.map [mYPos+1, mXPos] == 1; return false; }** **
I am trying to map every x,y position in the matrix to an X,Y position in world space, so then i read the pacman´s position for example 120,180 and i know where pacman is, reading the matrix´s position [12,18]. The problem here is that every time i want to read the matrix, i cant do a simple map[12,18], i have to invert the numbers → map[18,12] in order to read the correct tile i am in. I did the movement and it works, i am programming the enemy´s steering behavior and iam struggling really bad to make it work properly, because of this inverted coordinates problem i am most of the time guessing what to code.
I am wondering how should i do this properly, i am using old school coding, nothing of colliders, nothing of nothing basically, and since this game is really old, and the grid system is very comon in old games, i am wondering how is the correct way of doing it.
here the map just for a reference.

