As the sole engineer this time around for the Keyboard Cowboys, there was a lot of components that I had to contend with to make sure our game, Dude Ranch was functional. Character movement, lasso mechanics, Dude AI, a spawning system, scorekeeping, UI anchoring, etc. It was a lot of work!
Unfortunately, the curse of game design is the fact that a functional game is not necessarily a fun game! As such, I also had to dedicate a large amount of time making these mechanics “pop” in any way that I could. One of the most taxing layers of “juice” that I added to the game had to do with the dynamic camera movement.
When you walk around Dude Ranch, the camera follows the player around the screen as you would expect it to. Right off the bat there’s a bit of a wrinkle to this. Our game is presented with a 70-degree isometric view. Despair! This would cause some problems if we were to attempt to move the camera both horizontally and vertically, as illustrated here:

So what’s a programmer to do? The answer is actually surprisingly simple:

Create a parent CameraHolder object that always maintains a 0-degree rotation! Now you can rotate the camera to your heart’s content, and as long as you reference the CameraHolder for all of your movement, you’ll be able to move parallel with a player character at all times!

Okay, so we have a functional camera now. How can we make it feel better?
One of the ideas I came up with was to have the camera “snap” right to the action whenever the player managed to latch onto a Dude. No matter where the player was, or where the Dude was wrangled, I wanted to action to be perfectly framed.

This was accomplished through the magic of midpoints! After dusting off some old high school geometry skills, I took the position of the player character and the position of the wrangled Dude, then averaged the X and Y values in order to find the exact middle between the two every time. After that, I would just lerp the camera’s position to that target point.

This would ensure that the camera would always be positioned right between the player character and the wrangled Dude, no matter where either of them were at any time. Easy peasy!
But wait!
Our game is presented with a 70-degree isometric view. DESPAIR!!
This method would only work if our camera was looking straight-down at a 90-degree angle!
Not a problem! All it takes is a little dusting off of even more high school geometry. Allow me to explain with a poorly-made diagram I made in MS Paint!

Basically, our camera is looking too far ahead of the target point that it’s snapping to. In fact, it’s looking exactly X distance too far. If we can just move it back X distance, then it would be looking exactly at the target point. Lucky for us, we can do some simple trig to figure out what X is. We already know what Y is, and we know the degree of rotation on the camera, so we can use both of those to solve for X:

Nice, now every time we snap the camera to the midpoint of 2 objects, we can subtract X from the value to make sure that the angled view point of the camera is what lines up with the target point, rather than the camera’s position lining up with it instead!
…But we’re not done yet…
Stay tuned for Part 2, where I talk about what I had to do to make the camera dynamically zoom closer to the player as they struggle to wrangle in the thiccer Dudes on the Ranch.

Hopefully this was somewhat useful for folks. I’m a tad tired, so apologies if any of this is unclear at all. This camera ate up a lot of my time during this jam, so if I can somehow make it easier for future devs, then the struggles will have all been worth it. :heart:
Until then, feel free to check out the fruits of our labor by playing Dude Ranch here! We’ve been loving the reception we’ve been getting so far, and we’re slowly going through everyone who was kind enough to leave a comment on our page with plans to rate their games in the very near future!
‘Til next time! :pointright: :cowboy: :pointright: