How to make a character walk on a grid?

I’m working on my very first, 3D game in Blender. My project is a puzzle game, and everything is on a grid of sorts.

I’m trying to figure out how to make a character walk forward, backward, left, or right, and continue moving in the pressed direction until he/she has moved completely over one or more blocks. For instance, if you hold down an arrow key, the character will walk. Once you let go of the button, the character will stop at the nearest block center.

If you simply tap the arrow key, the character will walk to the next block completely.

[The character will walk to the next whole number, but will not stop on a decimal]
0 - 0.25 - 0.5 - 0.75 - 1

If what I’m asking makes any sense, how do I go about doing this?

You can create a move action. Then play it with loop-end mode.

As monster says, using actions is the best way.
When you press a button switch the player to a different state, in that state they move one space. When they’ve finished moving, switch back to the “command” state. This will stop them receiving extra commands or stopping half way between two squares. Have a state, and animation for each direction of movement.

For your first game it may be good to steer clear of grid based games. They are pretty difficult to get working properly, and require custom pathfinding code for AI, however, you could learn a lot from working on one, so just do whatever you feel happy doing. :slight_smile:

I feel that I should have mentioned that everything I modeled is exactly one Blender Unit large, so if I use the “snap during transform” option during editing, everything stays within their proper units. Isn’t there a way through Python to basically specify the following?

when w key is true [pressed]:
move along y axis .1 unit.

When w is is false [released]:
check if location on y is a whole number.
if true:
stop moving
if false:
Continue moving.
repeat this check.

This is a good approach

I suggest code tags to post code (edit in advanced mode).

Yes you can do that. But you have a design problem. While you designed everything in a grid, you do not want immediate motion (teleporting from one grid location to the next one). So you need to deal with “non-grid” locations. Playing an action with the above method, gives you an animation (over time) to end in a grid position. You can do such thing in Python too, but I do not think it is worth the effort.

So, through actions, I have made a walking motion which brings the character one blender unit forward. How should I go about having the character and armature actually translate one blender unit over after the animation is complete?

When I press “W”, the character takes a step forward and stops, as made in the action. Because it’s just a action however, and not an actual translation, when I press “W” again, the character jumps back a unit, then repeats the walking animation forward once again.

The true location of the character mesh and armature never changes.

I suggest you read the character guide in my signature