I'm looking for a technique to help the player navigate a narrow path while the character is in constant motion. When changing direction in junctions, it's pretty hard to time the direction change for a successful turn. With bad timing, the character just gets stuck as pictured.

pacman path

How can I make this easier for the player? (This is for a university assignment.)


1 Answer 1


You could "hot spot"-check areas adjacent to the character

hot spot testing

and immediately begin moving in a free direction if the appropriate movement key is held.

For example, if the player is moving right and holds the downward arrow key, they would continue moving right until the below hot spot becomes free. They would then begin moving down.

On platforms that allow multiple directional controls to be triggered simultaneously (such as the arrow keys on a PC), you may want to include an input queue in your control state to ensure the inputs process in order.

The original Pacman used a similar scheme, but even allowed the player to cut corners if they held the controls in the appropriate direction ahead of time like this!

  • \$\begingroup\$ Thanks, I'll give it some thought. How would this translate to ghosts though, if at all? My initial thought was to have the turns/junctions mapped like the boxes are and those would define what directions are available. With an NPC I would then randomly pick one (it doesn't have to match the original AI, something simple is adequate). \$\endgroup\$
    – romeozor
    Commented Apr 1, 2014 at 17:11
  • \$\begingroup\$ You could apply the same to the ghosts, choosing a random direction when detecting an intersection. The Pacman dossier is a great resource for these things: It even describes the logic behind the ghosts' motion. (As you say, you could also model the grid as a graph or a number of other data types.) \$\endgroup\$
    – Anko
    Commented Apr 1, 2014 at 17:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .