After three nights of trying various approaches, I still wasn’t satisfied with the camera control in my L-shaped room. Here’s a diagram of the issue in its most basic form.
The red outline represents the camera frame when the character is moving up out of the vertical shaft and walking to the left in the horizontal passage. In order for the camera to not clip the corner of the the room, and therefore inadvertently reveal the contents of the next room, it needs to slide straight up the vertical shaft, then move straight left in the horizontal passage. As it turns out, writing a general algorithm to accomplish this simple feat is, well, fraught. Nothing I had come up with over three nights was doing the trick, and I was beginning to go way off in the weeds, considering maybe doing a heuristic search with A* or something equally intense.
But then I was talking with my friend Jesse about the issue, and he had an interesting thought: maybe I don’t need to worry about corners getting clipped. Just don’t put anything in those corners, so there’s nothing for the camera to give away when it clips them. Honestly, I was kind of taken aback by this suggestion. I was approaching the problem like an engineer, trying to build a correct solution that would work in all cases with no fudging, and that meant handling the case where there was a room butting right up against that other one in the most inconvenient spot. In other words, I was building a system with rigid constraints and figuring out how to design levels around them, rather than designing levels and figuring out how to make them possible technically. It’s the classic programmer’s fallacy, and I walked right into it.
Still, I felt like a sissy for giving up, so I consulted my holy book, Super Metroid. What Would Samus Do in this situation?
Sure enough, Super Metroid’s map is composed almost entirely of strictly rectangular rooms. The majority are simply one-screen-wide vertical shafts or one-screen-high horizontal passages, taking a cue from the original NES title. In the few places where there are concave corners, they are almost always filled with empty space, avoiding the clipping problem entirely. The above area, Maridia, has the most convex corners in the game, and as you can see they all follow this rule. There’s only a couple places on the map where this principle doesn’t apply, where my camera problem would actually matter, and there the game just, well, cheats. I was actually kind of pissed off to discover this.
This is a pixel-for-pixel screen grab of the game. Notice how the rooms seem to overlap. They do. When you’re standing on the left, in the blue area underneath the monster head, the camera reveals part of where the tan-colored room should be, but all you can see is more of the same dark blue rock that makes up the background. Essentially, the game displays two completely different things for that region of the map, depending on where you’re standing. I guess I shouldn’t be so shocked — call it a tribute to Super Metroid’s excellent map and level design that I had taken it as an article of faith that this sort of thing simply wasn’t done. I have much to learn from the masters.
I played the game for an hour or so, wandering around various parts of the map where I was curious about camera controls. Approaching it as a game creator, I’m noticing all sorts of things I hadn’t before. I’m definitely planning a 100% run with my new-found critical eye and assembling a video analysis about the game’s camera controls, so watch for that in the coming months. Unless that’s already been done, in which case you should just point me to that analysis.