Warpers – Dynamic Cameras

DynamicCamera

I’m currently taking the course Big Game Project at Uppsala University – Campus Gotland, where the goal is to have, after 10 weeks, a working vertical slice of a game which might have the potential to become a product worth selling at a later stage.


We’re now five weeks into the production of the game Warpers and this time I’ll write about the camera system which gives Warpers a smoother feel than more traditional top-down cameras. Warpers have multiple scenarios where a cameras’ movement help the player understand what’s going on in front of them.

Focus Points

The camera location is determined by the average of a number of focus points. The focus points are three-dimensional vector locations which have a boolean state which decides whether the point should be considered or not then finding the final location where the camera should be. This true or false state for points makes it easy to create dynamic camera transitions when aiming or turning around to face another direction quickly.

The code to update the focus points are really simple as it’s only a loop which goes through all active points and returns an average.

void ADynamicCamera::UpdateTargets()
{
    FVector potentialLocation = FVector(0.f, 0.f, 0.f);
    int32 activeTargets = 0;

    for (auto& target : Targets)
    {
        if (target.Active)
        {
            activeTargets++;
            potentialLocation += target.Location;
        }
    }

    if (activeTargets > 0)
    {
        SetActorLocation(potentialLocation / activeTargets);
    }
}

Smooth Movement

When changing the camera location between the different points, you don’t want it to snap immediately to the target location, but rather have it move smoothly to the next location. This was solved using Unreal Engine 4’s built-in function for camera lag. The camera is attached to an object called “camera-boom” and the camera-boom have a property which dictates how fast the camera can be moved between locations. The feature is turned off by default and makes the camera snap to the intended location immediately, while when enabled and the lag speed is at a value higher than zero makes it advance to the target location at that speed in units per second. This makes the camera feel much more smooth in terms of movement.

To demonstrate, here’s the code that controls the camera movement for on-ground crew members.

void ACrewMember::updateDynamicCamera(FVector CameraVector)
{
    DynamicCamera->Targets[0].Location = GetActorLocation();
    DynamicCamera->Targets[1].Active = m_aiming;
    if (DynamicCamera->Targets[1].Active)
    {
        float camOffset = 0.f;
        if (m_currentWeapon)
            camOffset = m_currentWeapon->GetAimDistance();

        if (m_aimingWithMouse)
        {
            DynamicCamera->Targets[1].Location =
                GetActorLocation() + GetActorForwardVector() * camOffset;
        }
        else
        {
            DynamicCamera->Targets[1].Location =
                GetActorLocation() + CameraVector * camOffset;
        }
    }

    DynamicCamera->UpdateTargets();
}

The code should be quite easy to follow. First the location for the first focus point is set to the characters’ position. Then if the player is currently aiming, the second focus point becomes active, which offsets the value by the aim distance variable in the currently equipped weapon. The location of the second focus point is determined differently depending on whether the player is using a gamepad to aim or a mouse. Lastly the positions are re-calculated through the UpdateTargets() function.

Jarring Movement Issue and Solution

The character have a rotation speed which creates a camera issue where the camera arcs around the character when making quick turns in opposite directions. The CameraVector parameter is the solution to this issue, at least when aiming using the gamepad (I’ve yet to implement this solution for the mouse). This parameter is a vector of what direction the gamepad thumbstick is currently pushed towards. And by using this value you can have a smooth camera transition across the character when quickly changing the direction that the players’ facing, instead of the camera moving in an arc around the character every time the player is turning.

This figure which demonstrates how the camera behaved previously when the player turned from an angle of 0° to 180° and how it behaves now with the improved behavior.
CameraExplanation

That’s roughly how the cameras currently works in Warpers. There are many improvements which can be applied to the camera system but it’ll do for now. I’ll return next week to write more about another part of Warpers!

~Lead Designer and Programmer, Per “Gimmic” Johansson

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s