Footing Detection and Wobbly Bump

Recently we added this wobbling animation for when Bump is in a precarious position:

The only problem is our existing footing detection for Bump wasn’t really capable of the kind of precision to make the animation play at the right times. Traditional platformers have very simple systems for making these decisions, most use grids and have no support for rotation. Obviously when using a physics engine and having dynamically generated platforms like In The Dark’s lights, things get more complicated.  Bump’s footing detection has gone through five different major versions since we started.

Before  I can really explain the different methods we tried, it’s necessary to explain briefly the physics behind all the monsters in In The Dark. We use Box2d to handle the physics, just like many other indie games. Monsters are composed of one or more physics shapes, and these have forces applied to them to push them around the world. They are the only bodies in the game that collide with the lights and are otherwise no different from any other physics body in the game.

In the early tests of In The Dark, Bump simply had a separate “foot” shape. As long as it was colliding with something he could run and jump. The problem with this was that Bump would occasionally bounce a little bit when landing, or float up slightly when pushing against objects or running on slopes. This meant basically doing anything other than running on level ground caused little single frame animation spasms and would sometimes block the player from jumping.

The second method we tried was to use a “sensor shape”  as a foot. A sensor shape basically is just a box that knows if something is inside it or not. This was a little better but wasn’t always reliable. Under other circumstances it may have worked perfectly fine, but for some reason it was sometimes inconsistent and once or twice completely failed to register collisions. Soon we will be upgrading to the latest version of Box2d and when we do we may give sensor shapes another try and switch if they perform better. We still use sensor shapes in other situations, where per frame updates are less crucial.

Up until recently we used three point tests to determine if Bump was standing on anything, and if so what.  This turned out to be really handy, as being able to separately look at a left, right and center point meant we could know when bump was running from one object to another (like running from the floor onto a beam of light).  At the time we would disable Bump’s ability to rotate if all 3 points showed the same object, as it was a great way to prevent the occasional craziness that arises from using physics to handle these things. The problem was these single points could easily miss things, falling within cracks between different bodies, or completely missing very thin shafts of light.

So the points were replaced with short line traces. A line is traced just a few pixels,  from just inside of Bump to just below him. Surprisingly it turns out this isn’t significantly slower to process than the point test and is much more reliable. This system also allowed us to completely disable Bump’s rotation (except when he’s rolling around) and manually rotate him based on the distance before the line traces found something.  We’ve been using this method for months, the only problem is it doesn’t give enough info to reliably trigger the wobbling animation when we want it to.

We now use five line traces which provides us with a very clear idea of exactly what the ground beneath Bump’s feet looks like. I don’t expect there to be any more major changes in this department between now and the release of the game. If we make another 2d platformer in the future we will probably reuse this method.

If you found this interesting let us know and I will write more posts like this talking about other aspects of In The Dark.

Tags: ,

4 Responses to “Footing Detection and Wobbly Bump”

  1. joe Says:

    It’s always amazing how much work goes into details like these that seem so trivial from the outside.

    Very interesting I thought and I’d love to read more like it if you write them.

  2. Orvis Says:

    I definitely found this interesting. Thanks for sharing your insights and process!

  3. Dani Says:

    That was very interesting. Thanks for the article.

    I would look forward to it if you decided to write more about the technical aspects of developing In The Dark.

  4. » Blog Archive » Player Movement (or Why You Should Never Rely on Physics Engines) Says:

    […] pile of boxes caused all kinds of crazy things to happen. This is where the advanced foot detection I talked about before comes into play. According to the physics engine Bump can not be pushed to rotate, and using the […]

Leave a Reply

Preorder In The Dark!
Save 25% by Preordering!

$15 Standard Version:

$20 Special Edition:
Terms and Conditions