< Return to Video

How to Make a Good 2D Camera

  • 0:00 - 0:06
    Okay - let's say you're making a 2D game and you 
    need some kind of camera to frame the action.
  • 0:06 - 0:11
    No problem - just pin the camera 
    to the main character, right?
  • 0:11 - 0:12
    Wrong!
  • 0:12 - 0:18
    Do this and you'll have a camera that's jittery, 
    jumpy, short-sighted, and boringly static.
  • 0:18 - 0:20
    So let's fix it.
  • 0:20 - 0:24
    Here are five quick tips for 
    making a much better 2D camera.
  • 0:26 - 0:29
    First, let's talk about lookahead.
  • 0:29 - 0:34
    Basically - if you keep the character in the 
    middle of the screen at all times then you're
  • 0:34 - 0:37
    dedicating just half of the display 
    to the stuff that's in front of you.
  • 0:37 - 0:41
    No surprise, then, why this happens so often...
  • 0:41 - 0:45
    So it might be better to focus more 
    attention on the stuff that coming up,
  • 0:45 - 0:47
    and ignore the stuff behind you.
  • 0:47 - 0:49
    And there are a few ways to do it.
  • 0:49 - 0:53
    The simple solution is to simply 
    zoom the camera out further.
  • 0:53 - 0:56
    That means even if the hero 
    is dead centre on the display,
  • 0:56 - 0:58
    you can still get a good view of what's to come.
  • 0:58 - 1:03
    A more involved solution, though, is to 
    shift the camera in front of the character.
  • 1:03 - 1:07
    If you can only move in one direction it's enough
  • 1:07 - 1:10
    to simply offset the camera 
    from the main character.
  • 1:10 - 1:12
    That's great for endless runners and the like.
  • 1:12 - 1:16
    But if the player can travel both 
    left and right then you'll need to
  • 1:16 - 1:18
    adjust the lookahead based 
    on the direction of travel.
  • 1:18 - 1:23
    So in Cave Story there are 
    two camera positions - one
  • 1:23 - 1:25
    when you're moving left and 
    one when you're moving right.
  • 1:25 - 1:28
    They're both offset in front of the player,
  • 1:28 - 1:31
    which is perfect for a game about 
    shooting targets in front of you.
  • 1:31 - 1:36
    When you swap direction, the game slowly glides 
    to change from one position to the other.
  • 1:38 - 1:41
    New Super Mario Bros. U does something similar.
  • 1:41 - 1:46
    The camera is naturally biased on the 
    right side of the screen, ahead of Mario.
  • 1:46 - 1:51
    But if you start to backtrack for a short 
    period of time the camera will realise,
  • 1:51 - 1:54
    catch up, and swing further left of Mario.
  • 1:54 - 1:58
    And in Sonic Generations the 
    camera reacts to Sonic's speed.
  • 1:58 - 2:03
    It settles on the hedgehog when he's stood 
    still, but it moves further and further in
  • 2:03 - 2:06
    front of him as he picks up momentum 
    - until it reaches a maximum position.
  • 2:06 - 2:11
    This is not just for platformers, 
    though - in Hyper Light Drifter,
  • 2:11 - 2:15
    the camera is offset a few feet 
    in front of the hero's head so
  • 2:15 - 2:18
    no matter which direction you're facing, 
    the camera will frame what's coming up.
  • 2:18 - 2:21
    And in Luftrausers the camera tracks in front
  • 2:21 - 2:24
    of the player's plane - but only 
    when the throttle is held down.
  • 2:24 - 2:28
    That makes it possible to do those 
    sexy stall-and-swing-around shots,
  • 2:28 - 2:30
    without losing sight of your prey.
  • 2:30 - 2:36
    It's even easier to do this if the player has 
    a method for aiming, like in Nuclear Throne.
  • 2:36 - 2:40
    By centring the camera somewhere 
    between the character and the cursor,
  • 2:40 - 2:42
    you can get a better look at 
    the enemies you're shooting at.
  • 2:42 - 2:45
    It's a very natural way of responding to the
  • 2:45 - 2:49
    player's intention and framing 
    what they obviously want to see.
  • 2:49 - 2:53
    You can witness similar stuff in 
    bullet-based roguelike Enter the Gungeon,
  • 2:53 - 2:58
    clone 'em up puzzler The Swapper, and 
    blood-soaked rampager Hotline Miami.
  • 2:58 - 3:01
    Basically - ask yourself "what does the player
  • 3:01 - 3:05
    really need to see"? And then make 
    sure the camera isn't hiding it.
  • 3:06 - 3:09
    Next up - let's talk about cameras and jumping.
  • 3:09 - 3:12
    Because if you pin the camera to the character
  • 3:12 - 3:14
    then it's going to move the 
    screen every time you jump.
  • 3:14 - 3:17
    And if you're making a platformer - a genre that's
  • 3:17 - 3:20
    all about jumping - that's 
    a lot of camera movement.
  • 3:20 - 3:24
    This can make the player feel nauseous, 
    and make it hard to line up perfect jumps -
  • 3:24 - 3:29
    especially if the platforms disappear 
    beneath the camera when you lurch upwards.
  • 3:29 - 3:32
    So, there are two main ways to help with this.
  • 3:32 - 3:36
    One is to ignore jumps until the 
    player reaches a certain elevation.
  • 3:36 - 3:42
    In Donkey Kong Country: Tropical Freeze 
    the camera doesn't react to DK's leaps -
  • 3:42 - 3:45
    ensuring that the ground stays in 
    the same position at all times.
  • 3:45 - 3:48
    However, when you land on a 
    sufficiently high platform,
  • 3:48 - 3:52
    the camera tracks up and sets 
    a new baseline to work with.
  • 3:52 - 3:56
    This means that the camera moves when you've 
    landed, rather than shifting mid jump.
  • 3:56 - 4:00
    The camera can break these rules 
    in certain circumstances, like when
  • 4:00 - 4:04
    you're climbing a rope or swimming 
    - now it moves up and down freely.
  • 4:04 - 4:09
    Rayman Legends is similar: the frame 
    doesn't need to lurch up when Rayman jumps.
  • 4:09 - 4:15
    It can just track up in certain, predetermined 
    areas where the level goes beyond the frame.
  • 4:15 - 4:19
    The other way to fix this is 
    through the level design itself.
  • 4:19 - 4:23
    In a game like Shovel Knight, the 
    levels are designed with a maximum
  • 4:23 - 4:26
    height - which just so happens to 
    be the exact height of the screen.
  • 4:26 - 4:30
    This means that the camera only 
    needs to track left and right,
  • 4:30 - 4:35
    but never needs to move up and down - 
    allowing the camera to stay still for jumps.
  • 4:35 - 4:39
    Go even further and you can keep the entire level
  • 4:39 - 4:42
    in a single screen, which means the 
    camera doesn't need to move at all.
  • 4:42 - 4:45
    Which is perfect for precision jumping.
  • 4:45 - 4:50
    It also helps to offset the camera vertically, so 
    the hero is closer to the bottom of the screen.
  • 4:50 - 4:55
    This gives more vertical space to play with 
    and less need to move the camera up and down.
  • 4:55 - 5:01
    But perhaps the best tip to remember is that you 
    don't need to treat both camera axes equally -
  • 5:01 - 5:06
    it can do completely different things when moving 
    left to right, and when moving up and down.
  • 5:07 - 5:09
    Next - let's talk damping.
  • 5:09 - 5:13
    If the camera perfectly tracks the 
    character then it's going to react
  • 5:13 - 5:16
    to every single movement, no matter how small -
  • 5:16 - 5:19
    and that can lead to a camera 
    that feels erratic and jerky.
  • 5:19 - 5:23
    Especially when making precision 
    movements to line up a perfect jump.
  • 5:23 - 5:27
    One solution is to use damping 
    - simply have the camera ease
  • 5:27 - 5:30
    between its current position 
    and the character's position.
  • 5:30 - 5:32
    This will make it follow events more smoothly,
  • 5:32 - 5:35
    and won't immediately respond 
    to small shifts in position.
  • 5:35 - 5:41
    Though, be aware: if the camera is slow to 
    catch up to the player's movements you can
  • 5:41 - 5:44
    end up with moments where the character 
    is actually in front of the camera,
  • 5:44 - 5:48
    leaving even less screen real 
    estate for looking ahead.
  • 5:48 - 5:51
    Another solution is to impose 
    some kind of dead zone.
  • 5:51 - 5:54
    In Fez there's an invisible window where the
  • 5:54 - 5:57
    character can wander around freely 
    without the camera moving at all.
  • 5:57 - 6:01
    But if you push beyond that 
    window, the camera shifts.
  • 6:01 - 6:05
    This does mean that the character will be far 
    beyond the centre of the screen when walking -
  • 6:05 - 6:09
    but the camera is so zoomed out in this 
    game that it doesn't really matter.
  • 6:09 - 6:13
    So super responsive cameras can be 
    good for retro-inspired titles
  • 6:13 - 6:15
    that want to capture that choppy 8-bit feeling,
  • 6:15 - 6:21
    but otherwise even a tiny bit of camera damping 
    can make things feel more smooth and polished.
  • 6:22 - 6:25
    Now, the camera should usually 
    be focused intently on the
  • 6:25 - 6:28
    character - but you'll sometimes 
    want to frame other things, too.
  • 6:28 - 6:32
    So don't be afraid to move, 
    zoom, or halt the camera.
  • 6:32 - 6:38
    For instance, you can use the camera to draw 
    the player's attention to certain objects.
  • 6:38 - 6:40
    In the game Insanely Twisted Shadow Planet,
  • 6:40 - 6:45
    key areas like checkpoints and puzzle zones 
    have a sphere of influence around them.
  • 6:45 - 6:49
    If the player's spaceship enters 
    the sphere, the camera is told to
  • 6:49 - 6:52
    find the average position between 
    the key area and the spaceship -
  • 6:52 - 6:56
    framing both on screen and adeptly 
    drawing the player's attention.
  • 6:56 - 6:59
    The camera can also temporarily frame a scene.
  • 6:59 - 7:05
    Disney Illusion Island typically just follows 
    Mickey's movements, but it can also zoom out and
  • 7:05 - 7:10
    settle on a predetermined position to completely 
    frame a tricky platforming section or puzzle area.
  • 7:10 - 7:13
    When the player leaves, it 
    goes back to normal tracking.
  • 7:14 - 7:17
    The camera may sometimes need 
    to follow multiple things, too.
  • 7:17 - 7:24
    In the fantasy basketball RPG Pyre, the current 
    character is equally as important as the ball - so
  • 7:24 - 7:30
    the camera zooms and moves in an attempt to make 
    sure both are prominent on screen simultaneously.
  • 7:30 - 7:34
    You may also want to move the camera 
    for dramatic, cinematic-style framing.
  • 7:34 - 7:39
    In Inside, the camera usually just 
    tracks ahead of the player like a
  • 7:39 - 7:43
    normal platformer - but at key moments, 
    like when you're being chased by a pack
  • 7:43 - 7:47
    of rabid dogs - the camera moves 
    for a better view of your attacker.
  • 7:47 - 7:50
    You can also zoom the camera 
    in and out for effect.
  • 7:50 - 7:54
    In GRIS, the camera sometimes 
    tightly frames the hero,
  • 7:54 - 7:58
    and sometimes draws right out to 
    reveal the grand scale of a building.
  • 7:58 - 8:02
    And you can also restrict the camera 
    from looking at certain things.
  • 8:02 - 8:06
    Spelunky levels are surrounded 
    by an impenetrable rocky picture
  • 8:06 - 8:09
    frame - and the camera is forbidden 
    from going too far into this zone.
  • 8:09 - 8:14
    By locking off this section it means 
    more of the frame can be focused on
  • 8:14 - 8:16
    stuff that's actually relevant to the gameplay.
  • 8:17 - 8:20
    Finally, the camera can also be used to add juice.
  • 8:20 - 8:23
    To make the game feel more exciting and alive.
  • 8:23 - 8:26
    For starters there's screen shake.
  • 8:26 - 8:29
    The ancient art of simply... 
    wobbling the camera around.
  • 8:29 - 8:33
    This can be an effective way to sell an explosion,
  • 8:33 - 8:37
    an impact, a frantic struggle, 
    or a heavy-footed boss monster.
  • 8:37 - 8:40
    You can tweak the intensity 
    - and also the direction.
  • 8:40 - 8:45
    In Celeste, the camera wobbles in the 
    same direction as Madeline's dash,
  • 8:45 - 8:48
    to really sell the speed and 
    power of her special move.
  • 8:48 - 8:50
    There's also hit stop.
  • 8:50 - 8:53
    This is about adding a small freeze frame to the
  • 8:53 - 8:56
    game - which can subconsciously 
    increase the impact of an action.
  • 8:56 - 9:02
    Check out Katana Zero - when you kill an 
    enemy the action freezes for a split second.
  • 9:02 - 9:05
    The camera still shakes and 
    some particle effects still
  • 9:05 - 9:09
    ring out - but the action is frozen 
    in time, before starting back up.
  • 9:09 - 9:15
    When playing at normal speed this small hitch in 
    the action makes every hit feel more impactful.
  • 9:15 - 9:21
    In Hollow Knight, the camera stalls for 
    a long time when you, the player, take a
  • 9:21 - 9:27
    hit - which makes sure you register the mistake, 
    and gives you a brief moment to collect yourself.
  • 9:27 - 9:33
    And finally, the camera can move and zoom 
    for a short period to add further excitement.
  • 9:33 - 9:37
    In Dave the Diver, when you land 
    a catch the camera will suddenly
  • 9:37 - 9:43
    zoom in and frame the epic battle between 
    Dave and fish, before returning to normal.
  • 9:43 - 9:48
    All of these techniques add juice 
    - but quickly shaking and moving the
  • 9:48 - 9:52
    camera can be troublesome for some 
    people so providing accessibility
  • 9:52 - 9:55
    options - like turning off screen 
    shake altogether - is a nice touch.
  • 9:56 - 9:59
    So to wrap it up - the camera's job is ultimately
  • 9:59 - 10:02
    to follow the main character and 
    keep them on screen at all times.
  • 10:02 - 10:04
    But it can do so much more than that.
  • 10:04 - 10:08
    It can look ahead to focus on upcoming challenges.
  • 10:08 - 10:12
    It can ignore jumps to avoid endless movement.
  • 10:12 - 10:14
    You can add damping to smooth things out.
  • 10:14 - 10:18
    Use special rules to feature 
    and frame important events.
  • 10:18 - 10:21
    And make quick adjustments for impact and effect.
  • 10:21 - 10:26
    But remember that there's no such thing as 
    a perfect camera that works for every game.
  • 10:26 - 10:29
    it depends entirely on the thing you're making.
  • 10:29 - 10:34
    A slow and pensive platformer needs 
    a very different camera to a twitchy,
  • 10:34 - 10:36
    erratic arcade thrill ride.
  • 10:36 - 10:40
    But hopefully these tips give you 
    some good ideas for your own camera.
  • 10:40 - 10:44
    You can play with some of these concepts 
    yourself in my interactive video essay
  • 10:44 - 10:48
    Platformer Toolkit, where you'll find 
    a whole panel dedicated to the camera.
  • 10:48 - 10:52
    You can tweak the damping, zoom 
    in and out, add some lookahead,
  • 10:52 - 10:55
    and choose whether or not to ignore jumps.
  • 10:55 - 10:58
    And if you want to find out how 
    to implement this stuff yourself,
  • 10:58 - 11:00
    check the description to find links to resources
  • 11:00 - 11:05
    that provide more practical programming 
    tips for coding the camera in your game.
  • 11:05 - 11:07
    Thanks for watching and I'll see you soon!
Title:
How to Make a Good 2D Camera
Description:

more » « less
Video Language:
English
Duration:
11:38

English subtitles

Revisions