Creating the Game Player Controller part 2
The PlayerController class (CustomPlayerController.uc) part 2
With all the variables needed declared we can go on to implement the needed functions to make this controller do something worthwhile.
Copy the following code that is needed to set the behind view and rotate the pawn each frame. You could replace this entirely with a 2d textured cursor
simulated event PostBeginPlay()
{
super.PostBeginPlay();
SetBehindView(true);
}
event PlayerTick( float DeltaTime )
{
local Vector PawnXYLocation;
local Rotator NewRotation;
super.PlayerTick(DeltaTime);
PawnXYLocation.X = Pawn.Location.X;
PawnXYLocation.Y = Pawn.Location.Y;
NewRotation = Rotator(MouseHitWorldLocation - PawnXYLocation);
NewRotation.Pitch = 0.0f;
Pawn.SetRotation(NewRotation);
}
Next we will tackle the player viewpoint calculations. This is needed for the gun to shoot in the proper direction.
/**
* Returns Player's Point of View
* For the AI this means the Pawn's 'Eyes' ViewPoint
* For a Human player, this means the Camera's ViewPoint
*
* @output out_Location, view location of player
* @output out_rotation, view rotation of player
*/
simulated event GetPlayerViewPoint( out vector out_Location, out Rotator out_Rotation )
{
local Actor TheViewTarget;
// sometimes the PlayerCamera can be none and we probably do not want this
// so we will check to see if we have a CameraClass. Having a CameraClass is
// saying: we want a camera so make certain one exists by spawning one
if( PlayerCamera == None )
{
if( CameraClass != None )
{
// Associate Camera with PlayerController
PlayerCamera = Spawn(CameraClass, Self);
if( PlayerCamera != None )
{
PlayerCamera.InitializeFor( Self );
}
else
{
`log("Couldn't Spawn Camera Actor for Player!!");
}
}
}
if( PlayerCamera != None )
{
PlayerCamera.GetCameraViewPoint(out_Location, out_Rotation);
}
else
{
TheViewTarget = GetViewTarget();
if( TheViewTarget != None )
{
out_Location = TheViewTarget.Location;
out_Rotation = TheViewTarget.Rotation;
}
else
{
out_Location = Location;
out_Rotation = Rotation;
}
}
}
Ok next this function is rather important, you could check to see what it does when you will execute the game. Basically it forces the camera to reset itself to the default set by pawn. We will see in the pawn’s class definition that it defaults to TopDown. If you do not override this function it will always put you in first person as stated in the “ELSE”.
/**
* Reset Camera Mode to default
*/
event ResetCameraMode()
{
if ( Pawn != None )
{ // If we have a pawn, let's ask it which camera mode we should use
SetCameraMode( Pawn.GetDefaultCameraMode( Self ) );
}
else
{ // otherwise default to first person view.
SetCameraMode( 'FirstPerson' );
}
}
For the rest, redefine UpdateRotation and ProcessViewRotation that conflicts with the new camera mode.
function UpdateRotation( float DeltaTime )
{
}
function ProcessViewRotation( float DeltaTime, out Rotator out_ViewRotation, Rotator DeltaRot )
{
}
DefaultProperties
{
// Replace [YourProjectName] by your project's folder name
CameraClass=class'[YourProjectName].CustomCamera'
}
Thats it for the player controller. We will now tackle the Pawn so you can see about the default camera request mode.







