PlayerController Rotation, Firing

The PlayerController is responsible for ensuring that the camera is up to date with where the Player should be looking as well as starting and stopping the fire cycle.

UpdateRotation

This is the function that is used to keep the rotation of the camera up to date. We know that UpdateRotation keeps the camera upto date because its code updates the player controller's rotation based on the input values in aTurn and aLookUp. This is how UpdateRotation looks in PlayerController:

function UpdateRotation( float DeltaTime )
{
    local Rotator    DeltaRot, newRotation, ViewRotation;

    ViewRotation = Rotation;
    if (Pawn!=none)
    {
        Pawn.SetDesiredRotation(ViewRotation);
    }

    // !!!!!!!!!!!!!!!!!!!!!!!!!! GAM537/DPS937 Note: These are the lines that we care about
    // Calculate Delta to be applied on ViewRotation
    DeltaRot.Yaw    = PlayerInput.aTurn;
    DeltaRot.Pitch    = PlayerInput.aLookUp;
    // !!!!!!!!!!!!!!!!!!!!!!!!!! GAM537/DPS937 Note

    ProcessViewRotation( DeltaTime, ViewRotation, DeltaRot );
    SetRotation(ViewRotation);

    ViewShake( deltaTime );

    NewRotation = ViewRotation;
    NewRotation.Roll = Rotation.Roll;

    if ( Pawn != None )
        Pawn.FaceRotation(NewRotation, deltatime);
}

Notice that UpdateRotation is also responsible for taking into account any viewshake (such as from weapon fire) and for making the Pawn face in the same direction as the player controller. Finding this information for yourself involves a little bit of research, reasoning, and intuition based on the names of these functions.

This means that if we wanted to handle view rotation our own way or to subvert it entirely, this function would be the place for us to place our code.

Following the call-chain

If we follow the call-chain for this function, we find that it looks like the following:

  • PlayerTick
  • PlayerMove
  • UpdateRotation

In most programming languages, following the chain of calls would be simple. In UnrealScript, this is complicated by the fact that Actors could have states (see the notes on States). Notice that inside PlayerController.uc, there are 8 versions of the PlayerMove function, not counting the initial prototype. If we look at each of them in turn, we notice that almost all of them end up calling UpdateRotation within their code.

StartFire

This is the function responsible for starting a fire cycle. It accepts a byte (an unsigned integer of 1 byte-length) that indicates which firemode the weapon should fire (for example, rocket launcher has primary fire and alt fire). Notice that in DefaultInput.ini, this function is directly called from the key binding system to indicate that the user has pressed down on the fire button.

Here's the relevant section in DefaultInput.ini:

; Removed BaseInput.ini aliases
.Bindings=(Name="GBA_Fire",Command="StartFire | OnRelease StopFire")

Now that we know which function is responsible for starting a fire cycle, we know what part of the code to override if we wanted to change what the player does when the fire button is pressed.

For a breakdown of the line above, please see the notes on Input Binding Advanced.