Salomonsson.se
Dec 27 2014

custom 2D physics in unity - part 6

Try the current build

News in this build:

  • Refactored character controller system (more on that below)
  • Jump button is now space bar instead of up arrow (conflicted with ladders)
  • Disable gravity while on ladders (was buggy before)
  • Cloud platforms are disabled while climbing ladders (can climb down through them)
  • Down+Jump while standing on a cloud platform and you jump down through it
  • Removed that silly fist

Been some while since I last wrote now. Been doing some other stuff than Unity (some c++, and some updates to Ripple and its level editor). But now it’s time to get back to this little project again.

Something that bothered me a lot in the past was how fast it gets messy when implementing platform mechanics. You need need to keep track of if you are jumping, falling, standing on ground, climbing, ducking, sliding, hurting, attacking. And these states gets intertwined into each other. For example: what is a valid state for a charater to jump? He should be standing on the ground – unless if he’s climbing a ladder… or if he’s hurt or dead. And if the player pressed the jump button and the character lands on the ground without releasing the button then we shouldn’t automatically jump again until the button is released and pressed again.

My very small piece of code had already started to get messy this early on, so for a few days I’ve been refactoring it into smaller, more independant and stand-alone modules. This new version is completely rewritten, and all the previous functionality has been ported. Along with a lot of bugfixes. Still the physics feels a little weird, so some more tweaking is needed. I guess next step is to implement some simple enemies with the same character controller…