Character Movement

Aug 25, 2014   //   by Gavin Hayler   //   Blog, Reborn  //  No Comments

I have been super busy with freelancing work and working on Reborn (that’s the working title of the platformer game I’m making with Filip Orekhov), but I thought I’d take some time to write a blog about the progress so far.

I’ve been mainly working on the character movement and the weapons systems and combat. I’ve been trying to get a good base together that I can start adding other features on top of.

I’m just going to talk about the character movement for now. I’m writing a platformer framework code base  that can be reused under a large number of circumstances and game types (within reason, obviously) and is highly tweakable to be able to easily create very different feeling characters and motion. I’ve also been trying to wrap Unity’s 2D and 3D physics systems up behind a facade so that the core movement code can be used regardless of whether I’m using 2D or 3D collision. I’m taking things I’ve learnt from doing Tom Sparks (top down shooter/platformer), Neon Shadow (FPS) and my own 2D platformers and making the system generic enough to be able to support any of those types of games. So far it seems to be working out OK and the player character is feeling pretty good to move about.

Here’s a shot of what most of the configurable systems looks like (I’m using Hercules sprites for the main character from which is an awesome resource when you’re prototyping things and are rubbish at art)



First up, I have a class called MovementSenses which constantly updates with information about the character’s surroundings which I use to determine how the character should react. Like “Am I on the ground?”, “Is there ground in front of me?”, “Is there a ledge near my hand that I can grab?”, etc. There are a few rays that I can drag around to configure to the current character showing things like where the hands will be for ledge grabs and that kind of thing.

Next I have the main movement controller class which has a ton of tweakable values to get the movement I want. One thing I quite liked is the “Jump Gravity Arc” curve which is an animation curve that controls the character’s gravity while they’re jumping. Doing this enabled me to generate a huge array of jump arcs and to be able to tweak the arc until I was happy with it. I ended up using a base gravity on the jump, reducing gravity near the top of the jump to give a bit of hang time and then increasing it past the original value to pull the character down quite hard which gives the character a sense of weight but still feels agile and makes sticking landings more intuitive too. The movement controller is a state-machine inside but I’ve written it in a way that is (hopefully) easily extendable to be able to add new movement states as they are required. For example: the base MovementController class is only able to do running and jumping. Then I have the derived PlayerMovementController which adds more abilities like dodging, ledge grabs, wall jumps, etc. I’m still trying to decide what abilities are generic enough to be put into this class and which ones I should move into a more specific RebornMovementController class, but for now it’s fine. There are a lot of little tweaks in here that aren’t technically right but make the game feel better. For example, there is a period after running off a ledge when you can still jump; if you jump when you’re close to the ground but not on the ground, the character will jump when he hits the ground; if you’re not holding a run direction when you land after a jump, the character decelerates much faster (helping to stick landings); etc. These things are all cheating and being nice to the player, but without them players will find that your game controls feel loose/sticky/unfair/just plain bad. Player’s aren’t computers, so we need to help them translate their intent into the game world (or just try to predict their intent) without taking the control and challenge away from them.

As you can see, for this game I’m using the 2D physics system which is OK, but not great. I found a few instances of the character getting stuck in geometry or collisions not happening the way I’d expect and having to add work-arounds for some other things, but it’s functional for the most part and I think I’ll stick with it as it provides some functionality that the 3D one doesn’t and is supposed to be less expensive in terms of processing. The one thing I really liked is the PolygonCollider in that I can adjust it in the editor without having to create my own specific MeshCollider so that I can have a more complex collider shape than a capsule. Fil and I decided that we didn’t want to do the whole typical run into an enemy, take damage and be pushed back thing, but then I had to solve the problem of what happens if you jump on an enemy. Standing on them or floating above their heads wasn’t really that great so I went with the sort of crystal shard shaped collider which causes the player to slide of the top of enemies as you can see below. Herc’s friend there is titled Mr Bonjangles and hails from Golden Axe :)

enemy collision

Sometimes it feels perfectly fine and other times feels a bit weird and floaty, so I might need to address this in the future by either refining the collider shape or putting in something that, when colliding with an enemy, will increase gravity a bit or push the player further off the enemy to make sure they continue to fall at an acceptable rate and not slowly slide off at the rate of my daughter’s porridge on our walls.

Well, I think that’s enough for now. Will talk about the weapons system and combat or the camera controller next I think unless there are other requests… or I just find something else to talk about.

Leave a comment