UDN
Search public documentation:

MOBAKitPCCamera
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > Unreal Development Kit Gems > MOBA Starter Kit > PC Camera System

MOBA Starter Kit - PC Camera System


Last tested against UDK May, 2012

Overview


The PC camera systems is more of a traditional RTS style camera system. It supports moving the camera around by moving the mouse to the edges of the screen, tracking of the player's hero and it also uses a fixed height positioning system. The fixed height positioning system ensures that the camera is always at the same height regardless of the terrain below. This makes the camera feel a lot less jerky when moving around.

The relevant classes are:

  • UDKMOBACamera - This is the base camera class which provides a common interface for the game to use.
  • UDKMOBACameraProperties - This is an archetype class object which is used for data storage.
  • UDKMOBACamera_PC - This is the PC variation of the camera.
  • UDKMOBACameraProperties_PC - This is the PC variation of the camera properties.

Why use UDKMOBACameraProperties and UDKMOBACameraProperties_PC?


Using archetypes to store data which is used by UDKMOBACamera and UDKMOBACameraProperties_PC makes it much easier to iterate changes within Unreal Editor as it provides real time feedback as to what those property changes will look like in game.

UDKMOBACameraProperties Variables

  • Rotation - Constant camera rotation. This property sets the fix camera rotation and is usually pointed down wards in this case.
  • BlendSpeed - Speed at which the camera blends from one place to another. The higher number is, the faster that the camera will blend from one place to another.

UDKMOBACameraProperties_PC Variables

  • MovementPlane - This is a point on the plane that the camera uses as it's fixed height.
  • MovementPlaneNormal - This is a normal which represents the plane that the camera uses as it's fixed height. It's possible to have a sloped plane to make the camera move differently.

UDKMOBACamera


Functions

  • SetDesiredCameraLocation() - This sets the desired camera location.

Variables

  • DesiredCameraLocation - Current desired camera location.
  • IsTrackingHeroPawn - If true, then the camera should be tracking the hero.

UDKMOBACamera_PC


Functions

  • UpdateViewTarget() - This is the main function which is used by the camera to calculate where it should be.

Variables

  • CameraProperties - Reference to the UDKMOBACameraProperties_PC archetype.

UDKMOBACamera_PC::UpdateViewTarget()


This function is responsible for where the camera is placed in the PC version.

First, the function performs an early out by checking if the CameraProperties variable is none. If it is, then it just returns the default implementation.

Next, the functions checks if the player wants to move the camera around. It first checks if the hardware mouse position is at the edges of the screen, using a buffer of eight pixels. If the mouse is at any of the edges, then it sets the appropriate variables stored in CameraMoveDirection. It then adds any PlayerInput contributions, such as when the player uses the arrow keys or the WASD keys. CameraDirection is then normalized so that the final movement speed is constant.

If CameraMoveDirection is not zero, meaning a player is moving the camera and the camera was tracking the player's hero, then it should be disabled.

If the camera is tracking the player's hero, then the camera just uses the player's hero location as the desired camera location. Otherwise the camera's desired location is calculated based on the camera move direction and speed.

First the axes is grabbed. This is required to get the local coordinates based on the camera's rotation. This ensures that when the player wishes to pan the camera upwards, the camera then moves in the direction which represents up on the screen as this may not necessarily be Vect(0.f, 1.f, 0.f). We first handle the the up and down movement. The reason why CameraDirectionY + Rot(0, 16384, 0) is used is because CameraDirectionX is not the direction which represents up and down. Instead we need to adjust CameraDirectionY by 90 degrees to create that axis instead. It probably is more technically correct to use quaternions for a more accurate result; but this is fast and reasonable accurate. A similar calculation is then used for the left and right axis.

Once the DesiredCameraLocation has been calculated, a line plane intersection is then performed. The plane is defined in UDKMOBACameraProperties_PC by a point and a normal. By performing a line plane intersection, it is guaranteed that the camera's location will be height stable.

From there the camera is then blended to the CameraIntersectionPoint to produce the camera's location.

The camera's rotation is set to the Rotation value defined in the camera properties.