UE4 How To Implement Grid Based Movement?

To enforce a grid, take a world position, and transform to a grid position by dividing by grid size and truncating. Then find the center of each grid square by multiplying by grid size and adding half the grid size.

Typically you’ll want to use a flat ground at Z = 0, but you can also use line traces to find the “ground level” given a particular X, Y coordinate set.

Whenever you place objects, decide where to move to, pick user click coordinates, etc, you should convert them to grid coordinates. Then, when you need to place entities, turn them back into coordinates for the renderer to use.

Good grid sizes might be 50 units, or 100 units, depending on your design specifics.

2 Likes