Side projects, and non-profit work. Always in search of the indefinable hack.

Sunday, July 28, 2013

Grid Based Movement in Unity

If you have played old school games like Dungeon Master, Eye of the Beholder, the early Lands of Lore and Wizardry series or even more recent games like Legend of Grimrock, then you know what Grid Based Movement is. This is my implementation of grid based movement using Grid Framework by HiPhish. Feel free to use your own grid system.

Setup a scene and if you are using Grid Framework create a new grid.
Add an empty gameobject to represent the player. I also make the camera a child of this object and set the camera position to 0,0,0 so it is always looking forward from the centre of the player.

Add this script to the player object. If you are not using Grid Framework, you will need to change/remove the GFGrid variable and the first line in the awake method. All this line currently does is move the player to 0,0,0. In a later post the grid will be used to determine if a move is valid or not. You will also need to either create the inputs I have specified in the script or update the script to match your own. I use w,s,a,d for forwards, backward, stepleft, stepright and q and e for turning.