A technical rundown of gravity in SkyCrawler

Since gravity is a main feature and a core mechanics of my game, I wanted to write a post about it for quite some time.

The idea behind my gravity implimentation is surprisingly easy: find a collision point with a platform, get a normal in this point, use the tangent and the normal in this point as x and y axis. So, basically, multiply horizontal input by tangent vector, multiply vertical input (or gravity) by normal vector.

gravity_arrows.gif

It isn't really that simple, but having circle collider for character and capsule colliders for platforms helps a lot.

For jumping I would just fix normal vector until I collided with a platform. I also smooth "horizontal" movement in air, and to get horizontal velocity in local space I project character velocity on the tangent vector using dot product.

gravity_arrows2.gif

But that's a jam, so of course there are a lot of hacks. I actually have two implimentations of gravity: first uses default Unity physics simulation, and it is used for player character only. But because in the last day of the jam I added an enemy, that needed it's own gravity separate from player, I have a second one, which is a hardcoded gravity specifically for this enemy.

To see all this stuff in action, try out my game, SkyCrawler: https://ldjam.com/events/ludum-dare/47/skycrawler

art_promo2.gif