So in a previous post [hyperlink], I talked a bit about my work on the physics and character control for Emilia in Grumpywitch.
So what's my bear of the day? Slopes. Going up and down uneven ground can be a surprising challenge to implement.
So why is that? Well, the job of a character controller is to help you inhabit a character. Unless you're playing a game like QWOP or Octodad, you likely want your character to make small decisions without you. You want them to know where to put their feet on the ground, how to bend their knees, to climb hills and stairs that they know they can climb. You want them to be able to tell the difference between the floor and a wall, and not try walking right up (or through) the wall. At the same time, you don't want to have to prompt them to lift their feet and not trip on small inclines or steps. In general, you want them to be better at navigating the world than I am in the morning before my coffee.
So what are some things we have to think about?
When you run up the stairs, you probably want to keep running along the ground when you reach the top, rather than flying off like Tony Hawk on a half pipe. So we have to 'glue you to the ground' a little bit while you move.
Similarly, when you encounter a downhill slope, you probably want to run along that and not fly off to the right at your previous speed, so more 'Ground Glue' is needed. But we don't want that glue to interfere with your jumping at all, and we want you to still be able to run off the side of ledges (because where would the world be without running off ledges?)
So generally, when you press 'Left' or 'Right' while on the ground, Emilia needs to know where the ground is, what angle it's at, and understand that your horizontal input sometimes actually means vertical motion, or rather that you are moving left or right relative to the "Ground Normal" (what that bit of ground considers to be 'up'). This gets extra tricky because platformers often separate out 'horizontal' and 'vertical' motion to simplify some of the logic. Now we need to make sure our code can handle that 'Horizontal Motion' might not always mean 'X Axis Motion'.
In the original Castlevania, you needed to press 'Up' or 'Down' to go from the ground to get onto stairs, and if you forgot, Simon would usually fall off them and die. We probably don't want to go back to those days (unless you're into that. Maybe making a drunk person simulator, or a PSA about stair safety).
At any rate, I've just about finished sorting all this nonsense out (jump-through platforms are a tale for a different day), so hopefully I'll be able to hook up some of our artist's hard work soon.