Unreal Engine 4 Controlled Camera

So this is what I've been working on this week. Our Unreal Engine group project in Game Production needs a camera and the project lead was unhappy with the results from the other person meant to work on it, so I was offered the job. In four days, I finished 3 camera modes: the normal camera mode he set me to work on (which tracks the player vertically as well as having a specially programmed horizontal scrolling system), the "zoom and average" camera mode (which zooms and moves to keep all tracked objects within a bounding box), and the "cursor aim" camera mode (a mode made especially for aiming). You can switch from any mode to any other mode and the camera transitions smoothly, with ease-in and ease-out (which I did by taking the alpha value I'm using to lerp and running it through a cubic function). The programming was all done in blueprint.

If you don't want to see the explanations for all of the things I did, scroll to the bottom for the video.

The zoom and average was the simplest. Just find the max/min x and y values, set the camera's x and y values (or Y and Z value in this case, since we're doing a 2D game where the X axis is depth) to the average of the corresponding min/max, and use some very simple vector math to figure out how far to zoom out the camera.

The player track camera was quite a bit harder. First of all, I wasn't satisfied with lerp smoothing and how long it takes to come to a stop if you try to scroll slowly, so I decided to do my own velocity-based smoothing algorithm. It would have an acceleration rate and a deceleration rate, and figure out whether to accelerate or decelerate based on the distance and current velocity. I actually had to use calculus to figure out the proper equation to use. It would also calculate the best deceleration rate to prevent from overshooting or undershooting the target. Since the acceleration is updated every time the function is ran instead of continuously, this was causing inconsistencies with the speed in regards to the framerate, so I had to put it in its own tick function.

I simply used that to track to the player's height directly, and for the x value I was told to make a bounding area, and a marker on the left and right. If you hit the left side of the bounding area, the right marker is set to scroll to you. If you hit the right side of the bounding area, the left marker is set to scroll to you. The left marker will only scroll towards you when you're to the right of it, and vice versa. That was simple enough, but then there was the added problem of the camera scrolling onto the other side of a wall and obscuring the player. I fixed this with a simple line trace from the player, and even made it so the camera will slow down when it approaches the wall. My project lead was very pleased.

The last camera mode I went with was a pointer aiming based mode. This mode would allow you to aim the cursor and move the camera based on that. It uses a hyperbolic function to control the camera's depth movement based on the position of the cursor; outside of a certain distance from the center, the hyperbolic movement is smoothly transitioned into no movement by use of a cubic spline (this is yet another thing I had to use calculus for, I needed both the hyperbolic function and derived hyperbolic function).

Here's the result:

Featured Posts
Recent Posts
Archive
Search By Tags
Follow Us
  • Facebook Basic Square
  • Twitter Basic Square
  • Google+ Basic Square