HomeFeaturesTotally Accurate Battle Simulator

The unknowable chaos of physics in Totally Accurate Battle SimulatorTurns out that standing still is pretty hard

Turns out that standing still is pretty hard

“A lot of fun stuff happens when you try to do stuff with physics,” says Wilhelm Nylund, head of Landfall Games, and the intelligent god behind Totally Accurate Battle Simulator’s legions of gangling warriors.

And yet physics has given him an enormous amount of grief over the course of TABS’ development - as well as all the other games he’s made at Landfall. Physics, after all, makes everything harder. “If you want to do something in the game, you need to figure out how to do it with physics instead of just doing it,” he tells me. And that’s why TABS, which is all about watching ridiculous parodies of extreme violence, is great.

Take standing. For TABS, even standing is the result of intricate physics systems. Each unit is a ragdoll which naturally tries to collapse in a heap on the ground, since every body part has mass which the game’s gravity continually pulls downwards. So to get a unit to stand, Nylund adds upwards forces on its torso and head which act like a marionette’s strings, pulling it upright. To ensure a unit only stands when there’s ground directly below it, he shoots a raycast with a length of around the unit’s height directly downwards from its head. Only if the raycast hits the ground is the upwards force added.

Then, to make the unit stand firmly on its feet, the game checks whether its feet are touching the ground. If they are, then it checks how far the point of connection is from the head. The closer the head is to the point of collision, the more force is added, compelling it to stand up more vigorously; if it’s fully upright, then it gets less upwards force.

Then, to give the unit the sense that it’s balancing on its feet, Nylund gives it a script which also works out when the unit should fall over. This script checks the mid-point of the unit’s feet and compares it to its centre of mass. When perfectly balanced, the two should align. But if the unit is, say, leaning forward, the mid-point between its feet will be behind its centre of mass and it will fall forward. To correct that, the script will pick up a foot and move it in the direction that’ll bring the mid-point closer to the unit’s centre of mass.

So that’s standing. Now walking. Most body parts have a script that take a role in walking motions: the thighs pendulate back and forth; the feet are subject to upwards and downwards forces. “So, when the right leg should be moving forward, the thigh rotates forward and gets some force added upward,” Nylund explains. “When that leg is going backward, both forces are inversed, so the foot pushes into the ground and the leg rotates backwards.”

“There are so many systems! I think we might be at iteration six or seven in total reworks of the animation system. We even threw out the entire codebase twice and started from scratch.”

Physics governs how a unit holds and swings its weapon, too. The point at which the unit’s hand holds a weapon is a joint that locks it in place. Then every weapon has a relative position with the torso that it wants to be held at. The sword wants to be in front, so force is applied to keep it there. “It’ll wobble around bit, but it always tries to stay 50 cm forward from the torso,” says Nylund. Then it has a relative rotation it wants to stay at. The sword likes to point upwards, while the spear always wants to be rotated so it points forward.

This is the animation curve that defines the samurai’s sword swing.

To swing a weapon, a unit first saves the direction in which it wants to hit, which generally goes from the point of the weapon – what Nylund calls the force point – to the enemy’s torso. Then, it defines the swing’s force with an animation curve. The curve starts at zero, then usually curves downwards for a moment, adding to the tip forceawayfrom the target, and then rises high, adding lots more forcetowardsthe target. “You get a bit of a wind-up, a tell that they will make a strike.”

All of this is the work of years of trial and error, of Nylund feeling his way through systems. Or as he puts it: “It’s a lot of fighting with the physics to get the look you want.” There are so many variables involved in simply getting a solider to hold a sword correctly. “It could be what angle the hands are, how much the weapon weighs, how much force it needs to stand upright, how the joints for the hands to the weapon are set up, how stiff they are, do they have lenience in the angle they’re connected? Any of those things could be the right thing to change, but you can’t know without trying it.”

But this solution still caused some extra messing around for Nylund when he came up with the samurai, a unit among the Dynastic faction. A way into developing the faction the team realised that it didn’t have an answer for ranged enemies. “They would lose against archers every time.” So the team thought, hey, wouldn’t it be good if the samurai could hit projectiles out of the air?

But some physics have so far proven impossible for TABS. Nylund would love to add a ball and chain and nunchucks to the game, but these weapons consist of more than one connected physics object. One object starts affecting the other, and then the second one reciprocates… It’s the mathematics equivalent of acoustic feedback. “It very quickly starts getting very unstable. I’ve tried a few times to make those weapons, but either the swings would be so slow that they don’t look interesting, or if you made them fast enough, you’d see the parts of the weapons would be dragged apart and shake.”

It might be frustrating, but at least it’s an understandable limitation. There’s one physics problem, however, that he’s never solved.

Stick Fight: The Game is a 2D fighting game that Landfall made before TABS. It runs in a slightly earlier version of Unity’s 3D engine, and since it’s 2D, Stick Fighters’ game objects, from its fighters to the stacked towers and bridges of boxes which fly apart during a melee, are all constrained in the Z-axis, so they can only move up and down and left and right on the screen.

Everything in the game is sandwiched between two invisible and frictionless planes, placed a metre apart. Nylund laughs at how ridiculous it is to add an extra dimension of collision to solve collision problems elsewhere. But it works.

“It’s so much a black box. So many things are happening that it’s not possible to actually understand, as far as I know, why something happens.”