GridMove

Author: Eric Haines (Eric5h5)

Description
This is used for controlling characters that need to move on a 2D map, as typically seen in top-down old-school RPG or strategy games. The character moves smoothly rather than jumping from square to square, but is confined to an user-defined grid.

Usage
Attach this script to the character that should be controlled. The variables are:


 * Walk Speed: The speed at which the character normally moves, in units per second.
 * Run Speed: The speed at which the character moves if the run button is held down.
 * Grid Size: How wide/tall each grid square is, in units. This can only be an integer, so grid sizes such as 1.5 aren't possible. (The grid isn't actually shown; that would be the function of whatever graphics you're using.)
 * Grid Orientation: Whether movement is on the horizontal (X/Z) plane or the vertical (X/Y) plane.
 * Allow Diagonals: If checked, diagonal movement can be done by holding down the appropriate buttons simultaneously. Otherwise, only straight horizontal or vertical movement is possible.
 * Correct Diagonal Speed: If checked, diagonal movement speed is physically the same as straight horizontal/vertical movement speed. That is, movement from (for example) 1,1 to 2,2 takes approximately 1.4 times as long as it would take to move from 1,1 to 1,2. If not checked, then moving from one square diagonally to another takes the same time as moving from one square horizontally/vertically to another.

The left/right keys or buttons are defined in the "Horizontal" axis as set up in the Input Manager, and likewise up/down is defined by "Vertical". A "Run" button also needs to be defined in the Input Manager. If no separate walk/run speeds are desired, line 34 should be commented out (so setting up the "Run" button won't be necessary).