BUILD | GAME DESIGN // 2D PLATFORMERS
Left-to-right: Super Mario World (low acceleration), Super Metroid (mid-acceleration), and Mega Man 7 (high acceleration)
character into several different polygons, each with different roles associated: so you’d (optionally) have the main central body, then a thin rectangle for feet, and two thin rectangles for sides, and another for head or some similar combination. Sometimes they are tapered to avoid getting caught into obstacles. They can have different physics properties, and collision callbacks on those can be used to determine the status of character. For more information, sensors (non-colliding objects that are just used to check for overlap) can be used, which I have described below. Common cases include determining whether we’re close enough to the floor to perform a jump, or if the character is pushing against a wall, and so on.
GENERAL CONSIDERATIONS Regardless of the type of platform movement that you have chosen (except perhaps for ‘type one’, as detailed in last month’s issue), a few general considerations do apply.
ACCELERATION One of the factors that affects the feel of a platformer the most is the acceleration of the character. Acceleration is the rate of change in
speed. When it is low, the character takes a long time to reach its maximum velocity, or to come to a halt after the player lets go of controls. This makes the character feel ‘slippery’, and can be hard to master. This movement is most commonly
associated with many entries in the Super Mario series. When the acceleration is high, the
Super Metroid’s Samus performing the ‘Space Jump’ (with ‘Screw Attack’ power-up); a distinct example of jump control
character takes very little (or no time) to go from zero to maximum speed and back, resulting in very fast responding, ‘twitchy’ controls, as seen in the Mega Man series. I believe that Mega Man actually employs infinite acceleration. That is, you’re either still or at full-speed. Even if a game has no acceleration on its
horizontal movement, it is likely to have at least some for the jump arcs – otherwise they will be shaped like triangles.
HOW IT WORKS Implementing acceleration is actually fairly simple, but there are a few traps to watch out for. • Determine xTargetSpeed. This should be 0 if the player is not touching the controls – maxSpeed if pressing left or +maxSpeed if pressing right. • Determine yTargetSpeed. This should be 0 if the player is standing on a platform, +terminalSpeed otherwise. • For each axis, accelerate the current speed towards target speed using either weighted averaging or adding acceleration.
Blizzard’s Blackthorne, with the character doing a long animation before shooting backwards
70 | AUGUST 2012
The two acceleration methods seen here are as follows: - Weighted averaging: acceleration is a number (‘a’) from 0 (no change) to 1 (instant acceleration). Use that value to linearly interpolate between target and current speed, and set the result as current speed:
vector2f curSpeed = a * targetSpeed + (1-a) * curSpeed;
if (fabs(curSpeed.x) < threshold) curSpeed.x = 0;
if (fabs(curSpeed.y) < threshold) curSpeed.y = 0;
• Adding acceleration: We’ll determine which direction to add the acceleration to (using the sign function, which returns 1 for numbers >0 and -1 for <0), then check if we overshot. This method produces more realistic results.
vector2f direction = vector2f(sign(targetSpeed.x - curSpeed.x),
sign(targetSpeed.y - curSpeed.y)); curSpeed += acceleration * direction;
if (sign(targetSpeed.x - curSpeed.x) != direction.x) curSpeed.x = targetSpeed.x;
if (sign(targetSpeed.y - curSpeed.y) != direction.y) curSpeed.y = targetSpeed.y;
It’s important to integrate the acceleration into the speed before moving the character, otherwise you’ll introduce a one-frame lag into character input. When the character hits an obstacle, it is a good idea to zero his speed along that axis.
JUMP CONTROL Jumping in a platform game can be as simple as checking if the player is on the ground (or, often, whether he was on the ground anytime on the last n frames), and, if so, giving the character an initial negative y speed (in physical terms, an impulse) and letting gravity do the rest. There are four general ways in which the
player can control the jump: • Impulse: Seen in games such as Super Mario World and Sonic the Hedgehog, the jump preserves the momentum (that is, in implementation terms, the speed) that the character had before the jump. In some games, this is the only way to influence the arc of the jump – just like in real life. There is nothing to implement here. It will be like this unless you do something yourself to stop it. • Aerial acceleration: That is, retaining control of horizontal movement while in mid-air. Though this is physically implausible, it is a very popular feature, as it makes the game’s character much more controllable. Almost every platformer has it, with exceptions for games of a similar ilk to Prince of Persia. Generally, the airborne acceleration is greatly reduced, so impulse is important, but some games (such as Mega Man) give you full air control. This is generally implemented through merely tweaking the acceleration parameter while you’re airborne.
Page 1 |
Page 2 |
Page 3 |
Page 4 |
Page 5 |
Page 6 |
Page 7 |
Page 8 |
Page 9 |
Page 10 |
Page 11 |
Page 12 |
Page 13 |
Page 14 |
Page 15 |
Page 16 |
Page 17 |
Page 18 |
Page 19 |
Page 20 |
Page 21 |
Page 22 |
Page 23 |
Page 24 |
Page 25 |
Page 26 |
Page 27 |
Page 28 |
Page 29 |
Page 30 |
Page 31 |
Page 32 |
Page 33 |
Page 34 |
Page 35 |
Page 36 |
Page 37 |
Page 38 |
Page 39 |
Page 40 |
Page 41 |
Page 42 |
Page 43 |
Page 44 |
Page 45 |
Page 46 |
Page 47 |
Page 48 |
Page 49 |
Page 50 |
Page 51 |
Page 52 |
Page 53 |
Page 54 |
Page 55 |
Page 56 |
Page 57 |
Page 58 |
Page 59 |
Page 60 |
Page 61 |
Page 62 |
Page 63 |
Page 64 |
Page 65 |
Page 66 |
Page 67 |
Page 68 |
Page 69 |
Page 70 |
Page 71 |
Page 72 |
Page 73 |
Page 74 |
Page 75 |
Page 76 |
Page 77 |
Page 78 |
Page 79 |
Page 80 |
Page 81 |
Page 82 |
Page 83 |
Page 84 |
Page 85 |
Page 86 |
Page 87 |
Page 88 |
Page 89 |
Page 90 |
Page 91 |
Page 92 |
Page 93 |
Page 94 |
Page 95 |
Page 96 |
Page 97 |
Page 98 |
Page 99 |
Page 100