Locomotion Smoke and Mirrors

Chris

If we’ve done our jobs right, Wind-up Knight is a fairly simple game.  There are only four inputs, and only two are ever needed simultaneously.  Sir Sprint, our heroic spring-loaded knight, runs forward automatically, removing the need for a classic directional pad or analog stick.  The challenge is derived from careful level design rather than a complex interface, and though the game is not easy, it’s straightforward.

Achieving a control scheme that is simple to understand and simple to operate, even for a straightforward game like Wind-up Knight, is actually a pretty complicated problem.  The term I use for this kind of code is player handling, referring both to the steering of the player’s avatar, and to the manipulation of the player himself.  You see, games that control well often do it by lying to the player, by fudging the simulation, by breaking the rules.

Good player handling code is often smoke and mirrors; the player presses buttons and sees a reasonable result, but in between those two operations a whole lot of code is working to ensure that the result is the best of many potential results.  For example, my friend Greggman discovered that Mario 3’s jumping rules change depending on whether or not a level has slopes in it.  Halo’s targeting reticle famously slows as it passes over an enemy to make it easier to target with an analog stick without using an auto-aim system. When Spider-Man swings, he certainly does not orient about the spot where his web connects to a building (at least, he didn’t in the swinging system I wrote).

Good player handling code doesn’t just translate the player’s inputs into action, it tries to discern the player’s intent.  Once the intended action has been identified, if the rules of the game allow it, good player handling code makes the action happen–even if it means breaking the rules of the simulation a little.  The goal of good handling code isn’t to maintain a “correct” simulation, it’s to provide a fun game.  It sucks to miss a jump by three centimeters.  It sucks to take the full force of a hit from a blow that visually missed.  It sucks to swing into a brick wall at 80 miles per hour instead of continuing down the street.  To the extent that the code can understand the player’s intent, it should act on that intent rather than on the raw input.  Do what I mean, not what I say.

Wind-up Knight appears to be a pretty simple game, but we actually pull a few tricks under the hood to make the game control the way you expect it to (rather than the way it would if left to a pure physics simulation).

Jumping

Sir Sprint does a lot of jumping, mostly from off of solid surfaces.  But he can also jump right after running off a ledge–for a very short amount of time, we’ll allow a press to the jump button to result in a regular jump, even though there’s nothing under his feet.  This is particularly helpful to players on phones that occasionally slow down; they shouldn’t have to die because the frame rate fluctuates right at the point of a jump.

 

We also allow wall jumping to occur while Sprint is in mid-air.  If you jump at a wall and hit jump again before he lands on the surface, Sprint will automatically flip, snap to the wall, and jump off it again.  This makes the wall jump feel a little more sticky, and it means you have a larger margin of error when timing a wall jump; even if you press the button slightly too early he’ll probably still make it.

Rolling

If you are rolling under a low ceiling and release the roll button, the knight will continue to roll until he reaches an area where he can stand.  In that case, if you hit attack or shield while rolling, the move will be queued up and executed automatically as soon as the knight stands up.  This lets you make moves immediately after exiting the roll state even if you press the button slightly too early.

The low-hanging ceilings, by the way, often extend invisibly on either side so that you don’t automatically stand up into some spikes.

Collision Detection

We have a fairly complicated “hit type” system to allow the rejection of legitimate collisions based on arbitrary game rules.  For example, if an enemy hits the player as the player is in the middle of swinging his sword, we ignore the hit to the player and instead reverse it to kill the enemy.  There are no double K.O.s in Wind-up Knight; when it happens, the player always wins.

We also ignore hits from falling things to Sir Sprint’s body region if his shield is up.  If the shield is up, all falling things are considered impotent.  This way, if Sprint runs into an object that has just fallen in front of him (missing his shield but not his torso), he won’t die.

Camera

The camera in Wind-up Knight is the second most complicated system in the game (the first being Sir Sprint’s locomotion code).  It watches where Sprint is going and tries to prepare itself ahead of time for dramatic changes in motion so that it never snaps or cuts jarringly.

The most interesting case is the way that the camera watches for upcoming walls.  If Sprint hits a wall he turns and runs back the way he came, which requires the camera to do a fairly dramatic sweep in the opposite direction.  To smooth that transition out, the camera searches for walls ahead of Sir Sprint and then moves to align itself to them.  However, not all walls will cause Sprint to change direction; low obstacles, for example, are probably going to get jumped over.

It took me quite a while to find a heuristic that could reliably detect upcoming walls but reject lower platforms.  In the end I went with a system that shoots three rays out from Sir Sprint’s position, and only accepts an upcoming wall if all three intersect the same plane.  You might not even notice that the camera speeds up and slows down in order to deal with dramatic orientation changes, but without that code the game would feel a lot less smooth.

Sometimes heuristics are not enough to get the correct effect, and you have to fudge it even further.  We place secret camera “hint” objects in pits and shafts that Sprint is meant to slide down so that the camera can move to ensure the upcoming floor is always visible even before Sprint begins to fall down the shaft.

Though helping the player complete an action that they intended to complete is almost always the right thing to do, it is possible to go overboard with this kind of system.  Games like Prince of Persia (the next-gen cel-shaded version, not the wonderful original) go so far in assisting the player that it’s almost impossible to actually fail.  If the assistance is so obvious that the player notices it, the game feels suddenly like a false challenge, as if it is on rails.  For Wind-up Knight, we chose a few areas to smooth out to ensure the best play experience, but the rest we left up to the physics simulation and the player’s actual prowess.

It may be smoke and mirrors, but good player handling systems are almost always focused on translating player intent, rather than player action, into game play.  Hopefully the work we put into this area on Wind-up Knight makes it a better game, even if most players never know it’s there.

This entry was posted in game design, game engineering, wind-up knight. Bookmark the permalink.

26 Responses to Locomotion Smoke and Mirrors

  1. Papa_Justify says:

    As always a great insight into clever game development. As a wannabe game developer and gamer myself I appreciate that you made that game the best possible experience for everyone.

    In fact Wind-up Knight is one of the few mobile games that I played longer than half an hour.
    (Though I never came beyond the first book, as I can’t manage to clear this one level with S-rank where I cannot find a certain coin 😛 )

    But keep up the good work, guys. I can’t wait to see what you got in store for us next.

    — PJ

  2. Sizzle says:

    On the subject of rolling -> I’ve noticed that if you hit the “Roll” button and release it immediately, Sir Sprint will roll for a little while before coming back to standing/running. However, if you hold the “Roll” button for a little while and release, he will go back to standing right away. It seems as though there is a minimal amount of time during which you must roll.

    A similar effect occurs with the “Shield” button.

    What were the motivations for doing it this way? Is it simply to prevent people from making the game look bad by quickly tapping the roll button and making Sir Sprint go up and down? Is it because the game needs to wait for an animation (like bringing the shield above your head) to complete? Is it to make the game feel better? Is it to fix issues where mashing those buttons would create too many animation blends? Is it a way of debouncing the button presses?

    I’m curious.

    Thanks,
    JC

    • Chris says:

      Good catch! I thought about discussing that choice in this post but decided against it.

      There is indeed minimum delays for both the shield and the roll (though there are some interesting rules in play here; jump -> dive -> roll has no delay, etc). These were inserted for two reasons: first because we noticed players tapping these buttons instead of holding them (which makes sense, since the jump and sword work on taps), and also so that the animation had time to respond. We never block physics on animation, but the roll in particular looks pretty bad if you spam it. But the main reason was to get people who are tapping the buttons to see the effect briefly so that the mechanism is understood.

  3. says:

    Very interesting post. I’ve been working on a game engine and the idea to cheat physics in the player’s favour and hint at where the camera should go hadn’t occurred to me. (Granted, I haven’t got far enough into the project to design actual levels, either… :p) I can see how you’d want to bend some rules to avoid those frustrating situations where you just barely fail to make the jump, and to make the game easier to play. I’ve played games that required very precise timing for wall jumps and they were just infuriating. (Hello, Super Metroid.)

    Even worse is when you lose because your character decides to automatically stand up at the wrong time or fails to jump because his feet were half a pixel past the edge of the platform. That kind of thing drove me nuts in the NES days! It’s the little things like that that can ruin an otherwise enjoyable game, so I’m glad to see a post explaining them for the rest of us!

  4. Mike says:

    Is there a reason that Android Market is telling me that Windup Knight is incompatible with my HTC Desire S?

    It is running Android 2.3.5 on the Vodafone network in the UK, from what I understand it should run OpenGL ES 2.0 given that I have found benchmarks (however I am not 100% sure of this).

    • Chris says:

      We don’t filter the Desire, but I understand that it has a problem downloading large files, and since Wind-up Knight is about 43 mb, Market’s probably saving you from wasting some bandwidth.

  5. Toby says:

    I bought the game to see how you implemented that. The game is 99 cents. Before the second(!) level, I am asked to buy a blade. Turns out

    a) I have to buy money to buy a blade (WTF?! Either you charge for the game or the in-app purchases)
    b) I cannot close the buying menu without buying anything

    So much talk about how you detect players’ intentions. My intention was to buy a game for 99 cents, not a money printing machine for you.

    Seriously…

    • Chris says:

      Nope, you don’t have to spend any money. Ever. The practice sword is free, and if you beat level two we’ll give you another sword for free.

      • FeepingCreature says:

        Clearly his intention was not to buy anything, and yet he came to the conclusion that he had to. Should maybe be treated as a UI bug?

      • Toby says:

        Yes, I understood that now. Still I don’t expect to pay for powerups if I have paid for the game. I’d rather pay more for the game (although I probably wouldn’t pay more than 1,99).

        And the buying menu has no close button, as far as I can see (the menu you get when you click the button after finishing lv. 1). Your only choice is to buy one of the swords. I had to initiate the buying process and then answer the system message with no to leave the menu.

        • Chris says:

          Yeah, the lack of back button on that screen is a bug. But as you mentioned, you can always get out of it by hitting Cancel when you get the system confirmation by hitting Buy.

  6. Bob says:

    After finishing WUK 1.3.5 on my Captivate I can only congratulate you guys on a job extremely well done. The control system is perfect, it helps where it’s needed and let’s you fail often enough that you don’t feel on rails.

    WUK is my favorite game on Android thus far and I hope that you keep making such wonderful games!

    BTW Market 3.4.4 should let you download big files so you can stop filtering for devices with the size problem (I think)

  7. Rahul Patil says:

    Hello,

    I am SGS User (Owner of Jetpack MOD ROM based on JW1 Gingerbread 2.3.7). My users are unable to search this game in Market. We have no issues regarding cache size as we have repartitioned it to 52mb. The only thing is, Wind Up Knight is not listed in Market when we search for “Wind up Knight”

    Have you removed this device from compatibility list? Is it problem with Market database or a ROM/Market app?

    Regards.
    Rahul

    • Chris says:

      It’s your mod. The only device we now blacklist is the Motorola DROID, due to that device having not enough physical memory.

      • rahul patil says:

        Thanks for reply. But when i open WUK via market after searching it on google. Market says this application is not compatible with your device

        • Chris says:

          It’s your mod. Market knows what your device is running and is telling you that there’s a problem. You should trust it.

          • Rahul Patil says:

            It’s not my MOD, Confirmed. I flashed Stock JVZ (Gingerbread 2.3.6 Original Stock Samsung firmware) and tried searching for Wind Up Knight but it was not listed in search results. Then I flashed JW1 (Original Samsung Stock firmware 2.3.6) and searched for Wind Up Knight but it was not listed in search results..

          • Chris says:

            Market filters its results based on what your system is running, and what your system says it can support. It’s your mod.

  8. nluckett says:

    What a wonderful game. My favorite iOS game this year. So good. And thank you for this insightful blog. Always nice to see the process behind the games.

  9. gabriel says:

    Awesome game, very well implemented. Horribly addictive. Just finished all achievments on ipad 2. Got medusa shield when i got to book 4, other than that, just vanilla or card items. Im going to give it a break, then go back qnd try to get all S’s w/ just vanilla/yellowjacket items. The one criticism/fault I found would be that it almost relies completely on luck to get the coins between the last 2 trap doors on book 3 level 6. I got them by using 3 fingers wildly tapping the jump button hoping he’d exit the roll, after dozens of tries. That was one of those excruciatingly frustrating moments. In fact, when I was going back through the game to get all S’s, after spending at least a half hour on just trying to get those coins, I actually moved on and did the rest of the game and came back to it, which was quite difficult to allow my OCD completionist self to do. Awesome game though. Anything else in the works?

    • Chris says:

      Good work! Actually, that area isn’t working quite the way it’s supposed to–we’ll have an update that corrects it soon.

      • Turpin says:

        FWIW, I have no problem with this section on Android. When WUK lands on the second of the trap doors you have a grace period before it opens. This is plenty of time to jump on to the wall then walljump back to the coins.

        Congratulations to all on an excellent game. It’s certainly one of the best I’ve played. A couple issues I have which you might want to address in the update (I’m playing on an HTC Desire Z with Android 2.3.3):

        * After learning to walljump, on quite a few levels it’s possible to fall in to nothingness by running back past the start point. For example, on Book 2 level IX (Roll with the Pack) you can jump on to the edge of the first gap you encounter and walljump back towards the start point. Before you run out of time you fall in to an undecorated pit.
        * On Book 4 level XII (Low Clearance) I’m occasionally crushed by the falling ceiling even when rolling. It’s slightly erratic but it seems to happen frequently if you jump in to a roll right before a falling ceiling (I get the impression that dives are sharper (and thus slower) than simply falling out of a jump). This happens quite reliably if I jump with the shield to get the coins in the first flame jet in the level then immediately go in to a dive/roll for the next falling ceiling. I get the impression that this is not intentional, and it’s very frustrating because it feels like something the player can’t control. However, I can avoid it most (but not all) of the time by landing on my feet before going in to a roll.
        * I’m finding the card on book 4 level XII (The Shaft) too difficult. It’s hard enough to jump off the wall and in to the small gap at exactly the right time, but then coming out of the roll and jumping immediately on to the wall seems almost impossible. Despite many tens of attempts (40? 50? I’ve lost count) I’ve only done it two or three times, but haven’t completed the other parts of the dungeon on the same run. I get that it’s the penultimate level and so should be tricky, but it seems so much harder than Turnover’s Fair Play.
        * Minor niggle: it’s irritating that I can’t go straight from the death screen back to the book screen. I have to restart the level then pause and go to the book. Since levels take a few seconds to reload on my phone, this can be quite tedious.

        All in all, though, 10/10!

  10. lendlord says:

    Complete game with all S ranks and all achievements=( What about new levels or second part of game?

  11. Ordel says:

    I’d like to congratulate you and the team, this game is just perfect! After all of the achievements, I just still can’t get enough of it. Absolutely brilliant, a pure joy to play and in my opinion the best iOS game along with my all time favourite, Cut The Rope!

    All the best for your next game, whatever it will be, you’ve already sold a copy! 🙂

    (A new fan of yours from Hungary.)