2D Platform Controller (Not physics based)

Play the demo here: Platformer PRO 2 – JNA Mobile

Arrows keys to move, up to jump, ‘r’ to restart level.


Hi guys,

been creating a 2D platform controller that will hopefully behave like one expects a 2D character controller to behave. From everything i have read and my own experiments it seems like using the physics system for this doesn’t work out too well… so I’ve started building this without using rigid bodies.

From the start it’s built to handle 3D characters in a 2D world, so depending on how far you want to tweak you should be able to get good results with 2D and 3D characters. Note that the example here is mostly using static bounds checking, however you can attach the collision detection to individual transforms and have them move with animations.

Here’s a video (note the character I have doesn’t have animations for all the events):

Current features:

  • Falls nicely of a square edged platform (unlike built in platform controller).
  • Can have normal and “pass through” type platforms.
  • Works with moving platforms.
  • Sends the following events (to drive animation): Idle, Walking, Running, Jumping, Stopped, Balancing, Hit Head
  • Lots of configurable parameters.
  • Jump height controlled by length of key press. You can jump further if you are running (configurable).
  • Works on iOS.
  • Not physics based, but can be combined with a rigid body for additional effects (ensuring layers set correctly).

Planned features:

  • Pushable blocks (non physics-based, you can move blocks by adding a rigid body at the moment, but its not as controllable).
  • Sloped platforms (slide down hills, etc).
  • Jump and grab the edge of a platform, then climb it.
  • More animations sent (Sliding, Sliding down hill).
  • Climbable ladders.
  • Force imparting scenery (springs/ trampolines).
  • More configurable collision checking. At the moment you can attach to a transform (such as a foot or hand) and also provide an offset. In the future I plan to add the ability to enable boundaries to be enabled/disabled on a per animation basis.

I would love suggestions on features.

A nice start to your game. Note the character appears to be flying when he jumps.

Thanks for your comments. At the moment I don’t actually have a game in mind for this, this is just to demo the controller.

Regarding the flying, there are plenty of parameters to tweak jumping. In this case there is a variable which is used to control how long the jump force is applied after leaving the ground. The purpose is to enable user to control jump height by holding down the jump button. I probably have it set too high :slight_smile:

EDIT: Might also be the animation, unfortunately I’m not a 3D animator.

Naah, it clearly is the speed/setup/parameters.
Had the same issue on our own game lately :smile:
Getting the jump to feel like a jump seems quite a challenge. Thin line between flying and jumping, as Creativita already put it :slight_smile:

Likely, although the animation does launch the character in the air though not just raise his legs, so its likely adding more “apparent” height than the physics alone.

I really need a nice 2D sprite!

Actually have a game underway using this now. But still happy for others to use/comment/etc.

Oh my gosh!!!That’s exactly what I need for my next project.How much will it be?

No idea yet. It will be a while before its ready for asset store, as my main focus is around now delivering the game that will use it.

We might be able to come to some sort of arrangement.

Some new updates and clean up of existing behaviour.

What are you using exactly to replace the rigidbody physics? Just translations driven by math curve or things like that ( specifically for the jump )

Jumping and movement are based on custom acceleration and velocity. Raycasts for collisions. Loosely based on the sonic controller.

So it is physics based, just not using Unity physics :slight_smile:

Added a web player… it might be a lil slow to download :slight_smile:

Hmm think I need to upgrade my website plan, so slow … ahh … bump!

I’d be very interested in seeing how this goes. I’ve been attempting to build my own controller for this very purpose.

For the game I’m working on, the character will change his height during the game. Is this going to be possible with your system?

Do you just raycast in the direction that the player is moving? How many raycasts are fired at a time?

Looks interesting.

Hi mate,

a character has a configurable number of RaycastColliders which is a custom class that has a number of attributes defining what the raycast does (as well as some GUI editor helper methods):

  • They can be different types (HEAD, FEET, SIDES).
  • They can be static or move with animations (for 3D characters).
  • They can be IMPORTANT or OPTIONAL (used for optimization).

A basic character uses the 2 for the feet, 2 for the head, 1 for each side. Raycasts aren’t very expensive as they are cast only a short distance with layermasks; there is some optimization to ensure you only cast when it is needed.

Depending on exactly how you set it up, it will probably work without any modification needed. If you don’t actually scale or transform anything (for example both sprites are 64 pixels high, one just has more transparency) then you would have to add a new transform to your character and adjust it when the character changes size.

EDIT: Oops, commented on the wrong forum.

More details about my character. He will have his actual height change in such a way that his legs will get a little taller, thus changing the height at which his head would hit a ceiling. His actual collision detection can be a simple box, though, so as long as there’s a way that the collision box can change size mid-game, I think we’re okay.

BUMP, haven’t really done a lot on this lately, but it will be used as the basis for a couple of upcoming projects. Feel free to send me a PM if you are interested.

couldnt find this page so replied on the youtube video, but this seem quite interesting, lots of people including me :stuck_out_tongue: are having problems with 2D movement in unity, surprisingly reading the comments here ur also using raycast almost the same way i been trying to use for the past 2-3 days but ur version looks just ways smoother than my custom character controller; ur not using rigidbodies and physics by any chance? cause i think thats my error, i got moving around, ladders, water physics float and sink, moving platforms and wall jumps but everything feels slightly wrong and is a bit buggy. is this project still underway? not even sure if i would be able to purchase it but i think a lot of people would be interested in this.

The core doesn’t have physics, although sometimes I add a kinematic rigidbody to the character for the sake of triggers (other version use the raycasts themselves to trigger actions). This is part of the problem I have quite a few versions of the asset used in different projects, there’s no one version that is ready for the asset store.

The version used in Sorlo is coded neatly enough to be in the asset store, but it is both simpler and also less optimized than other versions. A version used in another project is well optimized (works fine on lower spec iOS), but the code is a mess.

All that said your post has reminded me that I should clean everything up, add a few key features and release it!