Muno Profile picture
Nov 28 26 tweets 8 min read
How do you design a 2D GAME CAMERA that properly frames the action? A whirlwind tour of different solutions, animated! #pixelart #gamedev

The setup: you've made your platform game's player character and need to make the camera follow them. Easy, right...?
...Well, there's more to it than that. If you just lock the center of the camera to the center of the character, it won't give the player a very good view.

In fact, nearly half of the screen real estate is now dedicated to showing the ground texture... not helpful!
Easy fix: move the camera up a little bit! Now the player can see all of the blocks above, at least. But our work isn't done yet.

For one thing, the camera shows the menacing out-of-bounds void when the player walks near the edge of the map.
No problem: just restrict its position to within the edges of the map.
You may notice that it's difficult to see far ahead of the character while moving. Classic Sonic fans are familiar with this problem.

...So let's move the camera a little bit ahead of the player during movement! The effect scales with the current speed.
At this point, the camera serves its PRACTICAL function... but it still feels pretty cheap.

It's very rigid, and even small movements cause the camera to shift around a bit.

Let's fix that!
Idea: Instead of matching the player's x-position EXACTLY, we'll give a RANGE of positions that the character may be within before the camera will move (the blue box).

This area moves with the player, since the camera needs to account for player velocity like before.
Even so, it's still kind of jerky... we can fix this by smoothing out its movement with a lerp. So now, the camera moves more gradually.

By now, this camera is pretty good for walking and running!
...But if we try jumping, there's a lot to be desired.

It's pretty jarring for the camera to follow the player upward with every jump... in many games, there isn't even anything up there!
So let's fix that by locking the camera's y-coordinate in place from the beginning of the stage.
But now the camera doesn't work for vertical climbing levels... Hm.
Okay, compromise: the camera's y-coordinate DOES change (marked by the blue X), but ONLY when the character is grounded.

There's also now a bottom margin used for when the character is falling.

Now jumps look fine, and the climbing section works too!
Oh, but now landing on the blocks from before causes the camera to pan up...

Ideally, we want the player to still see the ground when standing on these blocks. What to do...?
This is an example where a camera's needs CONFLICT with one another.

You want platforms to keep the focus at ground level, but other sections of the game should allow climbing.

Luckily, there's a solution!
For situations like these, you need "camera bounds" that change the camera behavior for certain areas.

Here, when the character is within the yellow box, the camera's y-coordinate is locked. Otherwise, the y-coordinate will update when the character lands. Cool!
That should be the last piece of the puzzle for this little demo!

To show how far we've come, here's a comparison with the very first camera we tried (camera follows character x,y rigidly). The dynamic camera is much nicer, huh?
But there are still other considerations.

For example, what if we want the player to travel DOWNWARD here? Our current camera setup doesn't let the player see BELOW very well...
...so we could add a camera bound to shift the view downward!
Also, if the player goes above the camera, should it follow them?

In the old-school Mario games, it doesn't follow until the player lands on the ground.

It depends on the situation: is there anything of interest up there, or should the focus be on the landing zone?
In addition, you can add a special camera offset for certain actions, such as aiming a projectile attack.

This helps the player see what's ahead at key moments.
That's about it, thanks for reading, share/follow if you enjoyed!

Food for thought:
- What if you want the camera to zoom in/out at certain moments?
- How does a co-op camera work?
- What kind of design choices would you make if the main character had free-flight?
P.S. I made these gifs in Aseprite, like my prior thread on netcode.

To make things easier, I programmed the camera logic into an Aseprite script.

If you want to mess around with it, let me know and I'll shoot you the DL. It's... *lightly* commented. 😅
Check out the previous thread I made, which talks about programming multiplayer games!

...Don't expect these fancy threads to keep coming out this often. I made these during my free time over the short holiday break😅

Also you may be interested in my other fun animations ^^ twitter.com/munosnail/time…
Someone asked for the aseprite files so here you go! Open the .lua scripts for instructions. Don't download without your parents' permission.

drive.google.com/file/d/1ePZlTp…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Muno

Muno Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @munosnail

Dec 7
Some are asking "why wasn't this in at launch?"

In reality there's a lot that goes into a simple feature like this. Any new menu/UX requires a design process to make it a reality, but beyond that this feature also has some challenges attached to it.

Thread #gamedev
First off, ANY menu you design for your game needs to go through the same design process to make sure it's very intuitive, polished, visually appealing, and bug-free.

This is rarely enough to kill a whole feature on its own. But it's a consideration in budget/planning.
It's not just "add some buttons and make them do stuff" - you have to ensure that the buttons feel good to use, the navigation makes sense, etc.

I downloaded the update and I think this menu even has new sfx? And the menu animations are also well-done.
Read 15 tweets
Nov 23
How does ROLLBACK NETCODE work, and why is it so difficult to program? A whirlwind tour of different solutions #pixelart #gamedev

The setup: you have a video game with couch co-op (pictured) and want to add online multiplayer. Easy, right...?

(thread)
Well, it's not so simple. If you send each player's button presses over the internet (big arrows), there's some delay due to how far the signal must travel. So the inputs get out of sync between the 2 screens.

Notice that the order of the characters jumping changes.
...This out-of-sync thing is a problem because it can make a player succeed on one screen but fail on the other. A few frames doesn't sound like a lot, but it can be the difference between victory and defeat in an action game.

E.g. Mario gets/misses the coin.
Read 28 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(