1
\$\begingroup\$

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.)

\$\endgroup\$
1
\$\begingroup\$

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!

| improve this answer | |
\$\endgroup\$
  • \$\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 Apr 1 '14 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 Apr 1 '14 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.