Do you use Unity Characer Controller for our 2D platformer games?

Hi!,

I’m checking the built-in Unity Characer controller in my 2D platformer game. It is somehow working but it is pretty hard to get a goold old-school platformer feeling (ghost goblins, mario bross, etc… alike) what leads me to wonder if people is using the built-in characer controller for this or they are rolling their own and how they you doing it.

Any comment will be really welcomed.

Thanks in advance.

Sorry for the reup, but I would really like to hear some information from the pros. Could it be possible?

Thanks in advance.

if you have allot of character running about.
and as this is on iOS forum.

the Character Controller is slow. Perfectly fine for most platform, or if just using afew of them.

But watch out for the speed issue on iOS devices.

Thanks for the answer.

Have you tried to build a “2D” platformer based on a simple rigid body, or combination of them?

I am actually going thru this right now. My game is 2D and kinda platformeris. Anyhow i have a main hero, plenty of projectiles and the main camera. I move all via character controls. I have only done small tests on my iPod 3G and it runs at 30fps consistently. That being said tho, i am not a hundred percent sold on the charContrls. Not for any other reason than is there a better route?

I am considering rigidbodies, but the reseaon for the switch may be more that i want physics similation in the game and less about performance.

If i notice anything i will pop back.

i know that its not a 2d platformer… but didnt shadowgun used a character controller for their main character? In one of the videos from Unity it seems like it has one.
What would be the difference in performance when using it in a 2d platformer vs 3d fps?

Thanks for the comments.

@renman3000 one of the problems I have found with character controller is that it is difficult to customise for a 2D game. It shows its potential as a 3D character controller but for 2D games finer control is needed and it lacks on it. I will have to spend some time playing with rigid bodies to see what I can accomplish. I will inform here if you want it too.

@maik: the main caveat for me is the difficulty to accomplish old-school feeling with the character controller. Said this, The character controller could fit into a lot of other genres.

I just spent the weekend messing with the character controller/character motor/platformer input, and also testing similar inputs with the rigidbody method for attempting achieve precise controls with a 2D platformer.

Ultimately the answer is that for precise, specific 2d platforming controls, Character controllers just aren’t the way to go. The scripts that come with them may fool you into believing that game development is easy for a brief moment, but once you test for a while you’ll realize how inflexible CC’s are.

For me, this video pretty much sums up why character controllers are worthless for this task, an always upright capsule doesn’t work for platforming:

So I am going to write my own physics independent Rigidbody controller script, and hope it works! The problems I’ve been having is that collisiondetection for rigidbodies doesn’t work when the RB’s are moving fast. 9 out of 10 times the wall will block my player but the 10th time he’ll shoot right through and get stuck.

@hex, if you would like to share your methods of rigidbody controls send me a pm or post them here. I am sure we can all learn from eachother

I’m about 1/2 way through implementing a 2D platform controller. It is raycast based not rigidbody based, but so far seems to behave as would expect from 2D platform control. Let me know if you are interested in having a look/chat about approach/etc.

Do you think there are more performance differences with Raycast-based vs RigidBody?

I was more concerned about accuracy/expected behaviour, character controller is horrible for 2D as you slide off platforms in a very unexpected way. Pure rigidbodies are difficult to control, I’ve toyed with them quite a bit and never had good progress on getting the control I want, particularly difficult in my case as I want to support animated 3D character models (in 2D game world).

With raycasts I’m coding every aspect of behaviour, so it always does what I say… sometimes I might tell it do the wrong thing, but its my fault and I can sort it out :slight_smile:

Given that my main focus is iOS I will definitely be looking at performance.

JohnnyA, I’m curious about this raycast-based approach as I’m finding the standard character controller w/character motor script completely unfit for a 2D platformer namely because of the forced capsule collider used.

I’m surprised there isn’t a better alternative on the wiki or even on the asset store.

Are you basically rewriting the controller from scratch with many of the same features of the character controller?

I just went this whole ordeal as well and came to the same conclusions. The CharacterController having a capsule as a collider is not well suited for a 2D platformer. It lacks accuracy when standing on the edges of platforms due to the rounded “feet” of the capsule. RigidBodies and control via physics can work in some cases but doesn’t have that good old platformer feel. I also ended up going the raycast route and it works much better. The implementation is very much game specific but here are some of the ways it’s handled:

  • figure out your delta movement just as if you were using the CharacterController
  • fire 2 rays in the vertical direction of movement and 2 in the horizontal. Now you know what is in your path if anything
  • move fully if there are no collisions
  • if there are collisions move vertically first (or in whichever direction has the largest delta movement if you choose) then horizontally
  • rinse and repeat adding in any specific behavior required (ledge climbs, box push, double jump, etc)

Prime31, I am currently in the same position you found yourself. I too found that the Unity Character Controller feels like it truly was meant for 3d games, and I am working on an old school pixel platformer. Am I understanding that you didn’t make use of any RigidBodies on your 2D player controller?

@girl, RigidBodies had a pretty awkward feel when we tested them. Going with a raycast solution was the only way to get 100% control over all aspects of the control feel.

I started to implement my raycasting 2d character controller last night, and was able to get things working for ground collision and left and right movement. I did run into an interesting issue though. I noticed that my character’s movement was pretty jerky, though my framerate in editor was about 300fps. My character would also sometimes land part way into the ground at times. I started to pull my controller apart trying to see what was making it jerky, and brought it all the way down to:

void Awake() 
{
	thisTransform = transform;
	moveSpeed = 5.0f;
}

void Update()
{
	moveDirX = 1.0f;
	movement = new Vector3(moveDirX, moveDirY, 0.0f);
	movement *= Time.deltaTime * moveSpeed;
	thisTransform.Translate(movement.x, movement.y, 0.0f);
}

And still the movement of the character ( fully automated ) was quite jerky. I even made a quicktime showing the jerky movement:

I suggest downloading it, as Dropbox’s in browser player is not great.

I checked to see if the editor was respecting the VSync setting, but at least under OS X it seems like it isn’t. I then made a standalone build, with VSync on, and the movement was visually smooth.

This is painful though as one of the big advantages is to be able to play in editor, which currently is too jerky and the raycast check to stop movement doesn’t always seem to be perfect, allowing my character to be partially through the floor at times.

I am unsure why I am seeing this behavior, especially when I simplified my controller down to a +x translation script. Any thoughts you may have would be awesome.

Girl + Robot, I am in the exact same situation as you. I tried the raycast route as well, but the collision is unacceptable as sometimes the player will dip into the ground a bit before the ray is triggered. I’m not sure why that happens either.

TOB is wickedly playable and happily uses character controller. It does not use a motor. It only uses Move, not simpleMove.

Quite how you think that it would be any different from custom code is unbelievable. After all with .move you have no choice but to input exactly the physics you make yourself regardless.

TOB uses it as a robust way to not go though platforms. Of course you need to deal with slopes and inertia buildup yourself, but it only took me a day to get it where it is today, with all the inertia etc exposed for the designers to tweak.

Character controller is a bunch of raycasts. That’s all it is. Mine doesn’t creep down slopes or anything, just seems like the above dude’s video was using simplemove or something. Which you shouldn’t.

It does “suffer” the rounded corners at the very edges of platforms, but I liked that aspect a fair bit particularly on touch games, you need that tiny bit of warning time. It would be fair to ask unity if they’re willing to chop the bottom off with an option though.

Char controllers are very robust and I’ve yet to get it stuck in something I couldn’t get out of, which is really easy to screw up with your own raycasts. The rounded bottom issue can be hacked around by using a “trailing” raycast that prevents falling unless it’s clear. By trailing I mean it is always behind the player at the ‘width’ of the capsule (in 2D).

If this isn’t touching, then you allow the fall.

I’m not sure how many raycasts char controllers do, but I’d imagine around 8 to be right. A custom job would still need at least 4 if only casting in the direction of movement (meaning that nothing behind you will get detected)…

And just maybe rounded bottoms is a really good thing for platformers. Just because the technical limitations of the past meant it was pretty binary if you fell off the edge of a platform, it doesn’t make it right.

All our enemies simply use 2 raycasts since they don’t need to have such robustness.

Yea, I’ve gone back to the CC a while ago, and it really is perfect aside from the rounded bottom issue.

Hi guys, I had to answer a PM and I thought I would post my answer here so other people may benefit as well:

The trick is to override isGrounded and use a raycast at the “heels” (or back) of the character. Please note the red raycast at the back of the character in this image:

The red line is the raycast. If this raycast connects you overrule isGrounded like so:

reallyGrounded = controller.isGrounded;
if (Physics.Linecast…) reallyGrounded = true;

By overriding the result thanks to the raycast we know when to start applying gravity :slight_smile: I don’t actually do this in TOB because on touch screens, that small downward creep fits nicer with our game. But I did test it so I know it works very well.

Of course this only works with .Move but nobody sane should be using SimpleMove anyway.

EDIT VERY RECENTLY: I now do this in TOB too, but only for jumping up and down on the spot. We want the rounded effect but also want to ensure player has the rounded feel.