This is The Mechanic, where Alex Wiltshire invites developers to discuss the difficult journeys they underwent to make the best bits of their games. This time, mountain-climbing platformer Celeste and the importance of timing in its movements and kindness in its code.

Early last month, the makers of Celeste released the source code behind the game’s star, Madeline. Across 5472 lines and in variables like JumpGraceTime, DashHJumpThruNudge and DuckFriction, the code precisely defines her ability to run, climb, jump and dash, bringing her to life in your hands.

If you’re not a programmer, it’s difficult to figure out what the code really means, so I asked Noel Berry to explain how it coalesces into a character who feels so good to control. Focusing on her dash, the mechanic around which Celeste revolves, it turns out that a lot of it’s down to the game making her do what you expected her to do, and not necessarily what you actually did.

As you’d expect, Celeste’s dash is a little instant burst of speed which Madeline can perform in eight directions, including into the air. But it needs to be recharged by having Madeline touch the ground before it can be used again, so she can only dash once in the air. It’s a simple mechanic, easy to grasp but with depth you won’t immediately realise, and most of the game is built around this principle, placing spikes to dash around and giving limited opportunities to land and recharge.

The way it works is pretty straightforward. When you hit the dash button, she flips into a separate ‘dash’ state. A timer is set, her hair turns blue, and she’s given a set velocity in the direction you were holding when you hit the button. The timer then starts counting. For .15 seconds you have no control over Madeline, but then the game gradually gives control back while also decreasing her velocity until you have full control again and her normal state is reinstated. It’s all over in well under a second.

A huge amount of work went into making it all feel good, finessing such aspects as the way the game steadily gives control back. “If you wait too long and the dash comes to a complete end, it feels very stiff and no one wants that feeling,” says Berry. “There’s a lot of small things that people don’t tend to notice, except speedrunners.”

This is where the really clever stuff in Celeste’s movement design comes in. The game continually gives you the benefit of the doubt to maintain the sense of control. As much as Celeste is difficult, it’s a great deal less pixel-perfect than you might think. “A lot of our intentions with coding were based on what we think the player wants to do,” says Berry. “Instead of ‘miss and you’re done’, we want to make the difficulty about the environment and levels.”

One of the principles it uses is commonly used in games, the ‘coyote jump’. Named after the moment Wile E. Coyote hangs in space when he runs off a cliff, it gives a brief window of time in which you can still press jump after Madeline has run into thin air. Similarly, if her dash will slightly clip a wall, the game will correct her course so she isn’t stopped dead.

“We had to play with how many pixels you can dash around a wall or over a floor,” says Berry. “It’s only one or two, but was about getting to where it feels right and that comes from a lot of testing. We did a lot of testing.”

Berry and design partner Matt Thorson would invite friends to play, knowing they probably wouldn’t recognise anything was particularly wrong as they hit a wall over and over again. “But watching them you can see that’s not working. Sometimes it’s a level design problem where a wall isn’t right, and sometimes it’s a feeling thing where the player is too slippery here or not jumping high enough.”

But Celeste is careful about where it bends the rules. Many games tweak the way they read controller inputs in order to perform what players probably want instead of what they’re actually pressing. They usually do this by modifying deadzones and increasing the angles that relate to common directions so players will hit them easier. But Celeste only modifies the way it reads a joystick slightly, despite the fact that not dashing in the desired direction is the most common complaint players level at the game. With dashes needing to be pulled off in every direction, the game works best by giving equal weighting to each of the eight directions in which Madeline can dash. Well, almost equal. Because you rarely need to dash downwards, down-right and down-left have slightly wider thresholds.

“It’s a really tricky problem,” says Berry. “There might be stuff we can do with reading multiple frames of input, but then you have a problem if you’re averaging multiple frames and the player flicks the stick really fast because it could read it incorrectly. We wanted it to be as accurate as it could be, so it’s what the stick says it is.”

Much of the tweaking was made early in Celeste’s development, as the game evolved from an excellent four-day PICO-8 jam game Thorson and Berry made back in 2015. But once they began designing levels they had to be very careful about making changes to the way Madeline controls, because they’d affect all the work they’d done.

“There’s a mechanic we had for a while that was terrible but we thought would be cool,” Berry remembers. “When we first moved from the PICO-8 version we added wall-climbing and immediately knew we needed stamina but we had this thing where if you ran out of stamina on a wall you’d have to catch your breath by standing for one or two seconds. There were levels designed around having to catch your breath on a crumbling platform, but that mechanic completely destroyed the flow of the game. Nobody was having fun when they had to stop and do nothing for two seconds. So we kept decreasing the time and there was a point where it was .2 seconds and it was like, why are we doing this?” Berry laughs.

The duo were happy to take out things that did not play into the mechanics of the game, and later, once there were lots of levels, the changes were mostly down to Thorson finetuning. “He was changing floating points from .2 to .21 or something to get the feeling just right.”

Things happen in Celeste for far shorter periods than you think. Berry thinks back to the moment of freeze-frame the game performs when you collect the green crystals that refill Madeline’s dash when she’s in mid-air. When the game shipped it lasted .1 of a second, and watching videos of the game being played, he realised it was far too long. Now it’s just .05 seconds and it’s still very noticeable. “The human eye can really spot things,” he says.

In the same way, Madeline is in her full dash for only .15 seconds, but you really feel it, supported as it is by various visual effects, such as a flurry of particles that appears in her wake and screenshake which moves in the direction she dashes. “That’s something we play with a lot to make sure there’s impact on everything,” says Berry. “We really don’t like it when things feel floaty.” But they’re careful not to go overboard, balancing the effect so you feel it but are not distracted by it.

Once (if) you complete the game and embark on its B-Side challenges, Celeste begins teaching you new techniques which prove there’s more to the dash than first seems to be the case, allowing you to reach parts of levels you never thought possible. One of them is a long-jump like move. Jump as you dash along the ground and Madeline will inherit the momentum and leap further. It was inspired by an action in Towerfall, the previous game Berry and Thorson made, but there’s further depth besides. Delay your jump until the moment her dash refills and she’ll launch into the air with the dash’s additional momentum and she’ll also be ready to dash again.

This wasn’t planned: it naturally arose from the mechanics. But while it opened up ways the level design could be skipped, Thorson and Berry loved it. “Speedrunners could do all sorts of crazy stuff and it doesn’t interfere with casual players. The timeframe is small enough that no one does it by accident, but big enough that you can do it consistently.”

Several other techniques have emerged during the game’s development that Berry and Thorson wholeheartedly support, but not all exploits are equal. The game has a timer that displays the elapsed time for a run, and at launch it paused for menus and during cutscenes. “But then a few weeks after release people realised that in some rooms you could hit pause and restart and Madeline would be moved to her spawn point for the room, jumping her a few pixels forward and saving game time because the game timer was not running when the menu was open. I don’t know how many rooms were optimal to do that, but there were dozens of them, and that was not a fun thing to do. No one wants to do that. No one wants to open the menu every room they enter and restart.”

In play, all the systems which govern Madeline’s movement are invisible. She simply moves. But that effortlessness is down to months of tweaking of the values in her source code to help her do what players intend. “That’s why her class is so huge, it’s because we kept adding more details about specific instances,” says Berry. “That’s really important in a game that’s about movement, there’s a lot of detailing you have to do that doesn’t make physical sense, but it feels a lot better.”

You can take a look at the source code for Madeline’s movement here.