Last tech update covered how we move along sloped surfaces and dealt with tricky issues such as mantling up and into tunnels equal to our height. But a platform isn’t about just running along the ground.. its about.. platforming. That means jumping.
Step 1 : Leaving the ground
With our vector movement based approach it was relatively simple to get our character to jump. We merely used the existing horizontal velocity along the movement direction perpendicular to the normal of our ground surface and added a positive jump velocity. We do a quick sweep up to determine if our character has at least a minimum height ceiling above them and switch from ‘ground-mode’ to ‘air-mode’ for our movement.
Step 2 : Air Control
There are many key points for successfully creating jump logic in a platformer. Our character can influence their horizontal movement each frame in the direction the player holds the d-pad. This coupled with a jump height ‘kill’ (apply extra gravity when the user releases the jump button) allows the player to precisely control their motion in the air in a way that makes sense. If the player presses and holds the button they jump farther. If the player holds in a direction they attempt to move in that direction. If the player releases all controls the character attempts to stop moving and fall in the current location. While experimenting with motion it became very clear that stopping the character when no input is received is just as important as moving when a direction is pressed.
Step 3 : Landing
With our analog approach to movement using sweeps landing is accomplished by sweeping in the direction of motion, discovering the normal to the surface, and comparing that normal to what slopes are ‘landable.’ We preserve the horizontal motion of the character, switch to ground mode, and apply any extra time after hitting the ground to smooth out motion when we finally land on something solid.
Step 4 : Wall Hugging, Hitting our Head
Real physics aren’t always fun, that’s why we make fake game physics. When our character hits their head on a platform above them, we apply vertical and horizontal friction, but do not zero out their velocity. We then move our character along the ceiling in the direction perpendicular to the normal of impact. This allows the player to jump against curved ceiling, nudge around platform edges to get on top of them, and keeps motion fluid. These rules also apply to vertical slopes, so if a player is attempting to move into a wall their descent is slowed while they slide down it.
Step 5 : Playing with Friends
All the rules up until now have applied only to a moving character vrs a static world. Thankfully the same sweep tests, overlaps, and collisions also work great against other dynamic characters. By applying our same rules as before and preventing objects from penetrating each other, we merely perform the same logic as with our platforms and our characters can move freely around and over each other.
Step 6 : Rigging all the Things
Finally we’ve completed solving moving our object around our terrain. The final step is the incredibly tedious process of defining the bounding boxes of all our characters across all of their various animation states and frames. In order to do this we draw bounding boxes in ToonBoom Harmony and expert them per-frame into Unreal 4.