Overview

The camera system for players in Unreal Engine 3 is comprised of three main classes: Camera, Pawn, and PlayerController. These classes all interact to control the position, rotation, and any other special effects that should be applied to the player’s camera during play.

The PlayerController holds a reference to the Camera being used as well as the Pawn being controlled. The PlayerController takes in the input from the player and uses that to update the positions and rotation of the Pawn it is controlling. By default, the Camera passes off its update to the Pawn, which in turn updates the position and rotation of the camera.

By modifying one or more of these classes and the way they interact, the player’s camera can be set to show the world to the player using any perspective that suits the type of game you are making. By default, the player’s camera uses a first-person perspective with the option to toggle it to a third-person over-the-shoulder perspective. This can easily be modified to show the world from a top-down perspective, an isometric view, a side-scrolling perspective, or any other view your game might require.

Camera

The camera class represents the player’s view into the world. The position and rotation of the player’s camera determines the viewpoint from which the scene is rendered when displayed on-screen. The Camera class also contains properties for controlling the way the world is seen through the camera, such as setting the field of view, aspect ratio, etc. Cameras also have special effects that can be applied to them including such things as post processing, lens effects, camera modifiers, camera animations, etc.

Note that all FOV variables are full angles, expressed in degrees.

Camera Properties

General

PCOwner – Reference to the PlayerController which owns this camera.

CameraStyle – Current camera mode for this camera. Used to determine the style of camera (i.e., first-person, third-person, free, etc.) when point of view is not being overridden by the view target.

PRI – Player replication info used to track the same player through pawn transitions.

FOV

DefaultFOV – Default field of view for the camera.

bLockedFOV – If True, the camera’s field of view will be locked to the value of LockedFOV.

LockedFOV – Field of view to use when FOV is locked.

Aspect Ratio

DefaultAspectRatio – Default aspect ratio for the camera.

bConstrainAspectRatio – If True, the camera’s aspect ratio will be constrained to the value of ConstrainedAspectRatio.

ConstrainedAspectRatio – Aspect ratio to use when the aspect ratio of the camera is being constrained.

Camera Functions

General

UpdateCamera [DeltaTime] – Called once per frame to perform an update of the camera.

DeltaTime – The amount of time since the last update occurred.

GetCameraViewPoint [OutCamLoc] [OutCamRot] – Retrieves the camera’s location and rotation. This function should not be called directly. Instead, the GetPlayerViewPoint() function of the PCOwner should be called instead.

OutCamLoc – Outputs the camera’s location.

OutCamRot – Outputs the camera’s rotation.

ProcessViewRotation [DeltaTime] [OutViewRotation] [OutDeltaRot] – Called by the PCOwner to give the camera an opportunity to alter this frame's view rotation changes.

DeltaTime – The amount of time since the last update occurred.

OutViewRotation – Outputs the adjusted view rotation of the camera.

OutDeltaRot – Outputs the adjusted delta rotation of the camera.

FOV

GetFOVAngle – Returns the camera’s current field of view angle.

SetFOV [NewFOV] – Sets the camera’s field of view to the NewFOV value.

TransitionParams – Blending parameters to use when transitioning to the new view target.

UpdateViewTarget [OutVT] [DeltaTime] – Called per-frame to update the view target to it's new position, rotation, and fov. If using custom cameras (as opposed to overriding CalcCamera() in the view target actor), this is the key function to override to implement your desired behavior.

OutVT – Outputs a data structure holding the view target and point of view of the camera.

DeltaTime – The amount of time since the last update occurred.

Post Process Effects

Post process effects are effects applied to the rendered scene before it is displayed to the player. Each camera has the ability to apply its own set of post process settings that can override the world, volume, or default post process settings.

CameOverridePostProcessAlpha – Sets the influence of the camera’s post process settings with respect to the world, volume, or default post process settings. A value of 0.0 means the world, volume, or default post process has full influence. A value of 1.0 means the camera’s post process has full influence.

CamPostProcessSettings – The post process settings to use when the camera is overriding the world, volume, or default post process.

bEnableColorScaling – If True, color channels in the final image will be scaled using the ColorScale values.

InterpTime – Amount of time to take to interpolate to the new color scaling values.

Lens Effects

Lens effects are particle effects that are applied to the lens of the player’s camera. These lens effects can be used to create things like rain dripping down the camera lens, blood splatter, dirt or dust on the lens, etc. The camera class contains functions for applying these types of effects.

CameraLensEffects – Array of all particle effects currently applied to the camera.

Lens Effects Functions

FindCameraLensEffect [LensEffectEmitterClass] – Searches the lens effects applied to the camera currently and returns any of the matching type.

LensEffectEmitterType – Class of lens effect to search for.

AddCameraLensEffect [LensEffectEmitterClass] – Applies a new lens effect of the given type to the camera.

LensEffectEmitterClass – Class of lens effect to apply to the camera.

RemoveCameraLensEffect [Emitter] – Removes a lens effect from the camera.

Emitter – Lens effect to remove from the camera.

ClearCameraLensEffects – Removes all lens effects currently applied to the camera.

Camera Animations

Camera animations are animations that can be created within Matinee (or optionally in an external animation editor and imported) that use the translation and rotation information of the animation to offset the camera during play. They also provide the ability to animate any of the other properties of the camera that can normally be animated in Matinee, such as FOV or postprocess effects. This can be quite useful for creating effects like camera shaking, the hand-bobbing of a handheld camera, or any other animation effect.

bImmediate – Optional. If True, the animations will stop immediately, ignoring any blending times set.

Camera Modifiers

Camera modifiers are objects which, when applied to a camera, can modify properties of the camera. The CameraModifier class is the base class for these effects. By subclassing this class and overriding functions within it, completely custom modifiers can be created. The CameraModifier_CameraShake class is a good example of what can be accomplished with camera modifiers.

Camera Modifier Properties

ModifierList – Array of all camera modifiers currently applied to the camera

OuterRadius – Distance from epicenter where the effect of the camera shake ends.

Falloff – Exponent to use for calculating the falloff of the intensity.

bTryForceFeedback – If true, force feedback will attempt to be applied to any controllers being affected.

bOrientShakeTowardEpicenter – Optional. If True, any offsets in the camera shake will be applied relative to facing the epicenter, with the positive X-axis being towards the epicenter.

ClearAllCameraShakes – Removes all camera shakes currently applied to the camera.

Player Controller

The PlayerController is responsible for translating player input into game actions, such as moving a Pawn or controlling the camera. It is typical for the PlayerController's rotation to drive the camera rotation, although this isn't strictly necessary. When creating new camera perspectives, it may be necessary to update or override some functionality within the PlayerController class as how the player’s input is translated into the movement and orientation of the Pawn can differ with each type of camera. Some of the properties and functions relating to movement and cameras are described below.

Player Controller Properties

PlayerCamera – Reference to the player’s camera.

CameraClass – Class of camera to use for the player.

ViewTarget – The current view target of the player’s camera.

RealViewTarget – Player replication info of the view target of the player’s camera.

FOVangle – Field of view angle of the Player’s camera.

DefaultFOV – Default field of view angle to use for the player’s camera.

Player Controller Functions

GetPlayerViewPoint [out_Location] [out_Rotation] – This returns the point of view of the Controller’s Pawn. For human players, this is the camera’s viewpoint. For AI-controlled players, this is the viewpoint from the Pawn’s eyes. In this base implementation, it is simply the location and rotation of the Controller itself.

out_Location – Outputs the location of the player’s viewpoint.

out_Rotation – Outputs the rotation of the player’s viewpoint.

GetActorEyesViewPoint [out_Location] [out_Rotation] – This returns the point of view of the Controller or its Pawn if one exists. Essentially, this returns where the player is looking from and in which direction.

out_Location – Outputs the location of the player’s eyes.

out_Rotation – Outputs the rotation of the player’s eyes.

UpdateRotation [DeltaTime] – This updates the rotation of the Controller and that of the Controller’s Pawn based on the player’s input.

DeltaTime – The amount of time since the last update occurred.

ProcessViewRotation [DeltaTime] [out_ViewRotation] [DeltaRot] – This is called to allow for any modifications to be made to the controller's view rotation (e.g. clamping). This is called from UpdateRotation().

DeltaTime – The amount of time since the last update occurred.

out_ViewRotation – Outputs the player’s view rotation.

DeltaRot – Change in rotation due to player input.

PlayerMove [DeltaTime] – This calculates the new acceleration and rotation values for the current move and then calls either ProcessMove() (for single-player or listen servers) or ReplicateMove() (for network clients). This is simply a stub in the base PlayerController class but is overridden within certain states which involve movement, such as the PlayerWalking state. This function is called from the PlayerTick() function every cycle.

ProcessMove [DeltaTime] [newAccel] [DoubleClickMove] [DeltaRot] – This handles the current move on the client. This function is overridden inside certain states which require special functionality for movement.

Pawn

The Pawn is not only the player’s physical representation in the world, but can also be responsible for controlling the position and rotation of the player’s camera. It contains functions which can be overridden to create entirely new camera perspectives. Some of the camera-related functions are describe below.

Pawn Functions

CalcCamera [DeltaTime] [out_CamLoc] [out_CamRot] [out_FOV] – This calculates the camera’s viewpoint when viewing from the Pawn. This is the main camera calculation for the player.

DeltaTime – The amount of time since the last update occurred.

out_CamLoc – Outputs the camera’s location.

out_CamRot – Outputs the camera’s rotation.

out_FOV – Outputs the camera’s field of view.

GetDefaultCameraMode [RequestedBy] – This returns the default camera mode, as a name, that should be used for this Pawn. This is usually called by the controller when possessing the Pawn.

RequestedBy - The controller requesting the default camera mode.

ProcessViewRotation [deltaTime] [out_ViewRotation] [out_DeltaRot] – This gives the pawn the opportunity to influence the player’s view rotation and returns the final view rotation as the out_ViewRotation parameter. This is called from the UpdateRotation() function of the PlayerController.

deltaTime – The amount of time since the last update occurred.

out_ViewRotation – Outputs the rotation of the Pawn’s point of view.

out_DeltaRot – Outputs the delta rotation.

SetViewRotation [NewRotation] – Sets the rotation of the Controller, if one exists, or of the Pawn itself if no Controller exists.

NewRotation – New rotation to set the Pawn’s view to.

GetActorEyesViewPoint [out_Location] [out_Rotation] – This returns the location and orientation of the Pawn’s eyes, or the point of view of the player. For a first person perspective this is identical to the camera location and orientation. It is also the view point most traces will be performed from.

out_Location – Outputs the location of the Pawn’s eyes.

out_Rotation – Outputs the rotation of the Pawn’s eyes.

Customizing Camera Behavior

There are 2 main ways to implement your custom camera. The view target Pawn can implement CalcCamera(), or you can create a custom class extending Camera.

Implementing Pawn.CalcCamera() is useful for simple and straightforward camera modes. The tradeoff is that some functionality may not be fully functional via this method, including post process effects or camera animations.

Creating a custom camera class can take a little more overhead to set up, but is more fully featured. GameFramework.GamePlayerCamera is an example of this approach.

Examples - CalcCamera

Below, there are some basic examples of modifying the player’s camera perspective using the Pawn's CalcCamera() function and in some cases how player input is handled as well. These are not meant as complete plug and play solutions to all your camera needs. They are simply a jumping off point to get started creating your own custom camera setups.

There are obviously a great deal of other modifications that could and should be done to make these polished, shippable camera types. You might want to implement the ability to adjust the camera’s distance from the player in any of non-first person modes by scrolling the mouse wheel. Adding code to avoid the camera encroaching on world geometry in some of the modes might be a good idea if you are not planning to design your levels specifically to avoid such things. Also, changing how the crosshair is drawn instead of removing it completely would be a nice addition in some of the modes.

All of these examples will require a new custom gametype class to tell the game to use the new Pawn and PlayerController classes.

Note: In order for the new gametype to be used, you will need to make sure your maps have the correct prefix. We set the prefix to be "UDN" in our gametype so all maps will need to be named starting with "UDN-". It is also possible to quickly test the new gametype with any map in the editor by setting the Game Type PIE property in the World Properties for the map to the new gametype.

Example First Person Camera

A first person perspective is the default camera type for all pawns extending from UTPawn. This example pulls out the main parts that make up that camera type from each class involved and places them in new subclasses in order to better demonstrate the process involved in creating a basic first person camera.

Example Third Person Camera

A third person camera setup is also included as an alternate camera type for all subclasses of UTPawn. This example pulls the main parts out and overrides the default camera to be this third person camera.

Example Top-Down Camera

A top-down camera can be created by making some additional modifications. It is similar to the third-person camera setup, but also requires limiting the Pawn’s rotation, specifically its pitch as aiming up or down won’t be allowed.

Example Isometric Camera

A simple isometric-style camera is very similar to the top-down camera example shown previously. The camera is offset along two axes, X and Z, and then the pitch is rotated down to focus on the player.

Example Side-Scrolling Camera

A simple side-scroller camera requires not only controlling the camera’s point of view, but also modifying the way player input is handled. The player is only allowed to move left and right on the screen and is always forced to face the direction they are moving. The input is required so that the A and D keys move the player forward or backward.

Example - Custom Camera

This example takes a different approach than the previous collection. Those all made use of the CalcCamera() function in the Pawn class to modify the camera. In this example, a custom camera framework will be created that allows for easily plugging in different camera modules to quickly modify the camera behavior. Just as importantly, we have complete access to all of the camera features, such as post process effects, camera animations and effects, etc. In addition, the player controller class will add the ability to use player control modules to override certain aspects of the player movement and aiming.

The setup for this example is a little more involved than the relatively simple overriding of a few functions, as was the case in the other examples. This example requires overriding many of the same functions that were touched in the previous examples, but instead of adding or changing the functionality directly in those functions, those functions will simply look to the custom camera and control system to provide the functionality they usually perform.

The new camera class will essentially act as an interface to the camera modules. It contains a few functions for creating new camera modules and handling the case of the camera having a view target other than the player's Pawn. Its job beyond that is to pass on function calls from various Engine classes to the current camera module to handle. Similarly, the new PlayerController class references a controle module that is relied on to handle certain movement and aiming functions from the PlayerController and Pawn classes. This allows the camera and control type-specific functionality to all be contained in compact, self-contained classes which can be substituted at will to quickly and easily implement new camera types.

Base Camera Module

The base camera module class extends from the Object class and defines all the properties and behavior that will be common to all camera modules. Its one property is a reference to the camera that owns it. Some initialization and deinitialization functions are defined, but the main functionality in this class is performed by the UpdateCamera() function which calculates the new location and rotation of the player's camera and can apply any other desired effects or modifications.

This class is defined using the config(Camera) specifier so that any properties that should be configurable or persistent in the specific camera modules will be found in the *Camera.ini file. It is also defined as abstract so that it cannot actually be used. It is more like a template for the specific camera modules to build from and not a class that would ever actually be used itself.

Custom Camera

The new camera class extends from the base Camera class, overriding some functions and adding new functionality to handle the camera modules. The camera's main job in this system is to act as the middleman for the camera module as it is now handling the majority of the calculations.

Base Control Module

The base control module class extends from the Object class and defines all the properties and behavior that will be common to all control modules. It contains a reference to the controller that owns it as well as holding the current mouse cursor position. Like the base camera module, some initialization and deinitialization functions are defined which allow for any type-specific setup or cleanup that may be necessary. The rest of the class is made up of the functions that will handle the player movement and aiming as well.

This class is defined using the config(Control) specifier so that any properties that should be configurable or persistent in the specific control modules will be found in the *Control.ini file. It is also defined as abstract so that it cannot actually be used. It nothing more than a template for the specific control modules to build from and not a class that would ever actually be used itself.

Engine Class Overrides

Several engine classes need to be extended to be able to interface with the new camera and control system, mainly the PlayerController, Pawn, and HUD classes. A new gametype will aslo be created ot make use of these new classes

PlayerController

The new PlayerController class adds exec functions for changing the type of camera module being used as well as zooming in or out (how the zoom functions work is dependent on how the current camera module implements them). The ProcessMove() function of the PlayerWalking state and the UpdateRotation() functions are overridden to add calls to the control module. Finally, the GetPlayerViewPoint() function is overridden and modified to keep the camera from being destroyed and to force the PlayerController to use the new custom camera if it exists.

Pawn Class

The new Pawn class overrides the CalcCamera() function to simply return false, allowing the new camera system to always control the camera location and position. The BecomeViewTarget() and GetBaseAimRotation() functions are overridden to pass the handling of their functionality on to the camera and control system, respectively.

GameInfo Class

The new gametype class is a basic extension of the UTDeathMatch class which sets the new HUD, Pawn, and PlayerController classes to use. It also sets bUseClassicHUD to True so that the HUD class specified here will be used instead of the UTGFxHUDWrapper, which is hardcoded to be used unless this boolean is set.

Example Camera Module

As an example of using the new camera framework, a Top-Down camera will be set up. Making a new camera module is mainly a matter of implementing the functions defined in the base camera module class. Much of this will look familiar if you have gone through the CalcCamera() examples above.

Config Files

All of the files below should be located in the in the UDKgame/Config directory. Since some may be new additions, you will need to create those. Others can simply be modified to include the new configuration settings..

The DefaultCamera.ini file should be populated with the values for the various config variables found in the new camera classes. For this example, this consists of setting a default camera module class only.

The DefaultGame.ini file should have the [Engine.GameInfo] section modified to point to the new gametype and it also needs a section added at the bottom to specify the default control module class to use.

Once these are created and/or populated or modified with the desired configuration settings, a new UDKCamera.ini and UDKGame.ini file will be created the next time the game or editor is run.

Note: In order for the new gametype to be used, you will need to make sure your maps have the correct prefix. We set the prefix to be "UDN" in our gametype so all maps will need to be named starting with "UDN-". It is also possible to quickly test the new gametype with any map in the editor by setting the Game Type PIE property in the World Properties for the map to the new gametype.