Warning: call_user_func() expects parameter 1 to be a valid callback, no array or string given in /home/troygilbert/old.troygilbert.com/wp-content/plugins/akismet/widget.php on line 126
Movement Mechanics in “The Legend of Zelda” « Troy Gilbert

Movement Mechanics in “The Legend of Zelda”

Let’s start our deconstruction with the most basic feature of the player’s character, Link: his movement. Link’s movement displays a surprising amount of subtlety. If you play The Legend of Zelda for a while, you’ll notice that Link doesn’t ever get hung up on obstacles due to unexpected collisions, nor do you ever just miss a bad guy by a pixel or two when attacking him. Yet at the same time, you’ll notice that Link moves fluidly through the gameworld; even tough the environment is tile-based, you can tap the directional pad and link will move a single pixel in that direction. If you’re moving to the left and decide to go up, down or right, Link instantly moves in that other direction when you change directions on the gamepad.

What’s happening here is a very neat trick. While Link can move a single pixel at a time, in any direction, the longer he continously moves in any direction the more he gravitates toward aligning himself with the underlying grid of the screen. The tile grid for LoZ is 16 tiles wide by 14 tiles high (including 3 tiles for the status display at the top of the screen). Each tile is 16×16 pixels. Link operates on a half-tile grid, though (32×28 tiles, 8×8 pixels each). As Link moves, if he’s not currently aligned with the half-tile grid, he is adjusted, one pixel at a time, toward the closest correction. As a result, if Link is 4 pixels off alignment he’ll line back up with the grid after moving 4 pixels.

In case that description doesn’t make sense, here’s an exercise to help demosntrate the technique:

Assume Link is basically in the center of the screen, lined-up with a tile. In other words, Link occupies a whole tile, just as he would in a strictly tile-based game (like a traditional boardgame or wargame). If you tap on the directional pad to the left, Link will move one pixel to the left. If you tap again, he’ll move another pixel to the left. This is pixel-fine control, which makes Link’s movement feel fluid.

Now, if you hold the directional pad to the left, Link will move continously. As soon as you let up, he stops. If you hold left then immediately reverse to hold right, he instantly changes direction (as he does for up and down as well). This is basically lag-free, which makes Link’s movement feel responsive.

Okay, return back to Link sitting squarely on a tile. If you tap left twice he’ll be two pixels over the left edge of his starting tile. Now press up four times. You’ll notice that after each press Link will move up one pixel. But, he’ll also move to the right one pixel, either the first two times you pressed up or the first and third times you pressed up (I don’t have the game in front of me and I can’t remember the rate at which it corrects). So, even though you never press right on the gamepad, Link has now returned to the same horizontal position as he was when he started (before you moved him left two pixels). This is the built-in correction.

What does this correction do for you?

The correction prevents the subtle but annoying problem wherein the player would “snag” on the corners of objects that he anticipated passing by. The more the player moves contiously the more aligned Link becomes, which has the same effect as speed-sensitive steering in a car.

The correction also has benefits for attacking as well. When Link attacks (with his sword, for example), the “kill zone” lies in the tile(s) immediately along his facing direction. Since enemies align along a similar half-grid as Link, the correction serves to line up Link with his enemies (as opposed to missing the enemy by a few frustrating pixels).

Observant readers will observe (as they are known to do) that this “feature” doesn’t appear in the SNES sequel, The Legend of Zelda: A Link to the Past . Even though the gameworld is still tile-based, player (and enemy/NPC) movement is not strictly aligned on any grid. We get the same corrections though, but using different mechanisms.

Movement is corrected by “rounding” the corners of most things Link can collide with. Thus, when he encounters them the “physics” of the game deflects him at a 45-degree angle along his direction of movement (e.g., if he was moving north/up and encountered a corner he would move northwest/east until he passed the corner).

Attacking is corrected in a similarly interesting way. Instead of Link’s sword having a killzone along a straight line down his facing direction, his sword “swipes” in a large arc, an arc that happens to be pretty close to full two “tiles” in the gameworld (one directly in front and half above and half below). This allows the player to attack while slightly mis-aligned with an enemy and still land a blow.

The result for both actions in both games is the same: the player’s desire is successfully expressed in the gameworld, regardless of the potentially pedantic ways of the computer.

  • http://www.kingludic.blogspot.com Patrick

    I think you’re touching on a key aspect of good HCI, a sort of hueristic built-in to the system’s core dynamic where raw will is purified mechanically, like water through a filter, into an intentional motion.

    Of course, the way you write about it is much easier to read.

    Doom was such a genre king for precisely the same reasons, along similar mechanics as well (they used rounding I believe). I think Resident Evil operated with similar collision properties for their tank controls.

    What I’m wondering is, if the genre-kings of movement-dynamics-based games streamlined movement from discrete action to continous intent (you dig the poetry?) then what sort of streamlining mechanics must a social-dynamics-based game incorporate to aspire to genre-king status?

  • http://dual-system.blogspot.com Babalou

    Hello. I will follow you on this deconstruction adventure! Thanks for the great article!

  • http://twitter.com/benmc Ben Mc

    You may want to check again on the auto-correction when moving up after going 2 pixels to the right or left. We recently played the downloadable version on the Wii and I specifically noticed how it didn't seem to care about your grid position. I could walk right down a middle line of the floor in a castle.

  • lofi

    > what sort of streamlining mechanics must a social-dynamics-based game incorporate to aspire to genre-king status?

    euphemism, linguistic categories for communicating social status, flattery and little white lies are a couple of real-life mechanisms, not sure if their electronic translation is that different

  • http://fromclay.com/ Stephen Clay Smith

    I don't have both games to compare, but is it possible that the one for the Wii emulator and the one for the original system differ in some of the mechanics, such as auto-correction? It seems improbable that they would have precisely the same code on both.

  • vvtempo

    Wow this is truly amazing dude!


  • jakob

    > I could walk right down a middle line of the floor in a castle.

    Well, as the article notes Link moves on the half-grid, so walking right down a middle line would be expected. Walking just off a middle line, though, shouldn't work.

    I tried it in an emulator and Link was lining up just like expected.

  • Lowery

    It uses emulation of an original NES rom. So, it's in fact precisely the same code

  • bollocks

    ok now show us some examples in C++ and SDL genious

  • guest
  • jakob

    After some more research (emulator slow down), I noticed the article is not quite correct regarding Link gravitating towards the grid. Rather, it works just like a reddit poster outlined Bomberman's movement system: http://www.reddit.com/r/programming/comments/ai

  • troygilbert

    Nope, it's not collusion-based as it is in Bomberman. You can test it in the first screen of Zelda. You'll correct even if you don't collide. I know it's been several years since I wrote this, but at the time I had spent many hours exploring this feature. Very powerful.

    For the non-believers, I'll try to put together a demo with source.

  • Dave

    Not a non-believer, but demo with source would be cool.

  • http://www.willwinder.com/ Will

    I did something similar with an Ant simulator. There is a grid based tunnel system, while moving through a tunnel having a one pixel tile overlap with a filled in tile next to an empty tile was very annoying. My solution was to move the player in the right direction the rest of the way if they are blocked (i.e. they are slightly more than half way between two tiles and want to move up, that will cause them to move right until up is a valid move).

    Here's a video: http://www.youtube.com/watch?v=ZOkAxh378T0
    You can try this nds image out with a Nintendo DS emulator: http://github.com/drovor/DSAnts/raw/master/DSAn

  • Pingback: Required Reading « Roll For The Drop

  • Rebekah

    “even tough the environment is tile-based” was probably meant to be “even though…”

    Excellent article!

  • Rebekah

    “even tough the environment is tile-based” was probably meant to be “even though…”

    Excellent article!

  • Pingback: Design roundup #3. « Significant Bits

  • Demon Exh

    st… stop being a dickwad. HCI can stay the fuck out of video games thanks. It ruined personal computing software enough.

  • Pingback: I discovered two interesting articles. Read them. « Threeli.com

  • http://hfiainsurance.com/auto-insurance-rates auto insurance rates

    If you are looking for Auto insurance rates then please visit out site. Auto

    insurance is required by law.Auto insurance is something that you should have

    for your vehicles to protect yourself. If you have your vehicles financed then

    it is mandatory . Auto insurance can be expensive though and that is what often prevents people from purchasing it. You can find this at our site so don’t stress about it. That information is important so you can make sure you have adequate coverage on the vehicle.

  • http://danielcarvalho.com Daniel Carvalho

    I’d rather just combine a tile based system for creating levels, then per-pixel collision detection for the objects that reside within the world.

    So your characters and such can move freely within the world, one pixel at a time, and yet, building levels remains structured and organized. Kinda like the later example you gave of the Zelda games.

  • david

    great article. if anyone knows of any similar articles to this one post the links

  • Lol.

    Personally, I love the misspelling of genius, as an insult.

  • Pingback: Level Design Among Other Things | Video Game Design ISP Blog

  • TheRealMethuselah

    Well, I believe I’ve perfected Link’s
    movement. Emulated sub-pixel precision, 4-directional movement with no
    diagonals, snap to 8×8 grid, collision detection as in the original.
    I’ll be adding the entire first quest for exploration. Here’s a little
    demo of the walking/collision engine. https://skydrive.live.com/redir?resid=A37E28BF8E7B737B%219847&authkey=%21AF40y5noZtPFyXQ

    Arrow Keys – Movement
    X – Sword slash
    Esc – Exit