- Home /
Using raycasts or maps for navigating a tile-based game?
So I'm working on a tile-based game that involves a computer controlled character wandering randomly across the map. On the map, there are certain tiles the character can and can't walk on, and I'm wondering what would be the best method for having the character make legal moves.
Right now, I have the game map stored as a variable attached to the main camera, so I could have the character pull from that every time they want to move. My other thought was using a Raycast to determine the properties of the tiles surrounding the character, and making moves based off that. I was wondering if either of those would be faster, or if either is more "proper" in terms of game design. Thanks so much!
Answer by Eric5h5 · Dec 27, 2013 at 10:05 AM
Have a 2D array that represents the world, and look up cells in the array, where each cell represents a tile. This little demo for example has no physics; non-passable tiles are just a bit where if it's on that means the tile is non-passable and if it's off then it's passable. Tiles have various properties such as what texture to use, if things should collide, and so on. So you can just look in the cells of the map surrounding the cell the player is in. Unless there's some specific reason you need physics I'd recommend not complicating the design by including it (which means no need for raycasting).
Your answer
![](https://koobas.hobune.stream/wayback/20220613124937im_/https://answers.unity.com/themes/thub/images/avi.jpg)