Download

UE4 How To Implement Grid Based Movement?

Hey all. I’m currently working on a turn-based RPG which features grid-based movement. I was wondering how would one go about setting up such a thing? I’m aware there are templates in the asset store that do this but I’d rather do it myself as that way I know how everything works and can tinker with greater ease.

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.

1 Like

Thank you very much! This is of great help! You wouldn’t happen to know how to do the conversion process would you? I think it’d be a matter of getting the mouse position when clicked but the rest I’m less sure of.