Limited Grid-Based Movement in Godot 4.2 3D

Hi, limiting the character’s movement to a grid in 3D is similar to doing it in 2D, since you don’t seem to be using the y axis.

You can use the _input or _unhandled_input (prevents ui input from moving the player) to detect a key press. Or you do it in the process function. Then just add tile_size * direction (do not normalize it if you’re moving diagonally) to the player’s current position. You don’t need to use characterbody for this since you won’t be using move and slide.

If the player is already on the edge of the grid, don’t move them.

2 Likes