sega 500 playing with the camera jeff “ezeikeil” giles [email protected] jgiles
TRANSCRIPT
So far…
We’ve see that we can add a considerable degree of functionality to UT2003 just by the creation of a new game type.
…However it still looks a lot like UT
Today
We’re going to take our first steps towards fixing that.
We’re going to break the camera away from the player.
Behind view
So far, we’ve seen that UT actually provides us with a degree of functionality already through the console
Just type in “Behindview 1”
Behind view
Yup, looks like I’m behind my character. Typing “Behindview 0” resets the players
view.
It’s a simple Boolean flag…and yes, “true” and “false” work also.
Behind view
So diving into the code we find it defined in PlayerController as:
var bool bBehindView; // Outside-the-player view.
Hmmmm…... PlayerController …..that sounds familiar.
Behind view
It should…
If you recall from our custom game type, we were using controllers to access information in the pawn to figure out who killed who.
Behind view
We’ll talk about controllers and their various incarnations in a bit.
For now, we just need to know that ALL pawns have one.
Behind view
So, inside our HUD class, we’ve already learned how to access information stored inside any pawn.
Also that the HUD has a PawnOwner, and all pawns (which are sill alive) have a controller.
Hence, we should have access.
Behind view
Well actually, you do. Remember, UT is heavily dependant on
inheritance and the Playercontroller is a child class of controller.
The answer is some type casting.
Behind view
Look closer at the inheritance structure
Well, nuts. How do we make sure that PawnOwner.controller is in fact a PlayerController.
We can’t just cast it now…
Behind view
Time to meet a new friend know as the Isa() function.
This function is defined in the Object class as:
native(303) final function bool IsA( name ClassName );
Behind view
It simply returns true if this actor belongs to a named class.
Hey! Handy!
So how do we use it…
Behind view
This will cause the player to ALWAYS be drawn from behind.
To the code
function PostRender(canvas c){ super.PostRender(c);
if(pawnowner.Controller.IsA('playercontroller')) playercontroller(pawnowner.Controller).bBehindView=true;}
What are controllers?
Controllers are non-physical actors that can be attached to a pawn to control its actions.
PlayerControllers are used by human players to control pawns, while
AIControllers implement the artificial intelligence for the pawns they control.
They take control of a pawn using their Possess() method, and relinquish control of the pawn by calling UnPossess().
What are controllers?
Controllers receive notifications for many of the events occurring for the Pawn they are controlling.
This gives the controller the opportunity to implement the behavior in response to this event, intercepting the event and superceding the Pawn's default behavior.
What are controllers?
To put this another way… The Controller classes define how a pawn,
or group of pawns, act, think and behave in their world.
More specific functionality is implemented in the child classes.
Behind view
Open the Controller class & give it a look. Here are *some* of the variables it looks after.
var Pawn Pawn;
var const int PlayerNum; // The player number - per-match player number.Var float SightCounter; // Used to keep track of when to check player
visibilityVar float FovAngle; // X field of view angle in degrees, usually 90.var globalconfig float Handedness; varbool bIsPlayer; // Pawn is a player or a player-bot.varbool bGodMode; // cheat - when true, can't be killed or hurt
Behind view
//AI flagsvar const bool bLOSflag; // used for alternating LineOfSight tracesvar bool bAdvancedTactics; // serpentine movement between pathnodesvar bool bCanOpenDoors;var bool bCanDoSpecial;var bool bAdjusting; // adjusting around obstaclevar bool bPreparingMove; // set true while pawn sets up for a latent movevar bool bControlAnimations; // take control of animations from pawn (don't let pawn play
animations based on notifications)var bool bEnemyInfoValid; // false when change enemy, true when LastSeenPos etc updatedvar bool bNotifyApex; // event NotifyJumpApex() when at apex of jumpvar bool bUsePlayerHearing;var bool bJumpOverWall; // true when jumping to clear obstaclevar bool bEnemyAcquired;var bool bSoaking; // pause and focus on this bot if it encounters a problemvar bool bHuntPlayer; // hunting playervar bool bAllowedToTranslocate;var bool bAllowedToImpactJump;var bool bAdrenalineEnabled;
Behind view
As you can see, it goes on. So now that we know more about what
controllers are, lets give the HUD another look.
If we kick open HUD.uc, one of customHUD’s parents…we see:
Behind view
var() PlayerController PlayerOwner;
var() Pawn PawnOwner;
var() PlayerReplicationInfo PawnOwnerPRI;
var() Console PlayerConsole;
Hey looky, there’s our PawnOwner object that we’ve been using to access the controller.
Behind view
…and right above it var() PlayerController PlayerOwner;
Giving us direct access to the owning player.
Notice that this is just for HUMAN players.
Behind view
Making some changes, we can condense our code to
function PostRender(canvas c)
{
super.PostRender(c);
playerowner.BehindView(true);
}
Custom Controllers
Now that we know about how controllers access the pawns, it’s apparent that how we are setting the behindview is not very good object orientation.
…It really should be done inside the controller.
Custom Controllers
So comment out that PostRender function. We don’t need it anymore.
Well create our own custom controller class to deal with this.
Custom Controllers
I’m just going to derive one off PlayerController and set the bBehindview to true in the defaults.
class CustomController extends PlayerController;
defaultproperties{ bBehindView=true;}
Custom Controllers
And in our game type we need specify that we want to use our new controller
PlayerControllerClassname="eze.CustomController"
That should do it… To the Code.
Custom Controllers
But there is a whole wack of stuff that UT needs to know about to make the game run which is missing…
Change the parent to xPlayer and give it a shot.
Back to the code
Custom Controllers
Uh, not quite…But at least it runs now.
We need to override one more function…well an event actually.
“Heh?” You say? “What’s an event?”
Custom Controllers
The "event" keyword has the same meaning to UnrealScript as "function". However, when you export a C++ header file from Unreal using "unreal -make -h", UnrealEd automatically generates a C++ -> UnrealScript calling stub for each "event".
Custom Controllers
The function we over ride is defined in playercontroller as:
event PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
With a rather long function definition.
Custom Controllers
So lets give this a shot…
class CustomController extends xPlayer;event PlayerCalcView(out actor ViewActor, out vector CameraLocation,
out rotator CameraRotation ){ bBehindView=true;}
Custom Controllers
Looks like it works…
But what’s all this boxy stuff?
Try moving…see what happens.
Custom Controllers
This is an interesting side effect form not calling the super.
The new code:class CustomController extends xPlayer;event PlayerCalcView(out actor ViewActor, out vector CameraLocation,
out rotator CameraRotation ){ super.PlayerCalcView(ViewActor, CameraLocation, CameraRotation );
bBehindView=true;}
Custom Controllers
And everything is right in the world.
We now have a 100%-can’t be change chase cam. It’s always in behind view.
Go ahead, try typing behindview into the console.
Custom Controllers
A bit about the PlayerCalcView event
PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
ViewActor: is which is passed in. Usually which one your looking at…but not necessarily.
CameraLocation: The point the world which you are viewing from.
CameraRotation: the cameras rotation in the world.
Custom Controllers
This gives us total control of the camera & where we view the world from.
If we don’t call the super and add of a few lines, we can track as though he’s on a security camera.
Custom Controllers
The new code:
event PlayerCalcView(out actor ViewActor, out vector CameraLocation, out rotator CameraRotation )
{ ViewActor=self; bBehindView=true; CameraLocation=Location; CameraLocation.Y+=100; //so we don’t start inside our player}
Custom Controllers
Notice how the camera tracks me from my start point…keeping me dead center I the screen.
Custom Controllers
This is cool! We can now do whatever we want to the camera. THROUGH CODE!
But there are a few things that we don’t have.
Custom Controllers
For example the player no longer pitches up or down…Always looking at the horizon.
That and the crosshair no longer indicates what we’re shooting at but remains fixed in the center of the screen on top of the player.
Custom Controllers
However these are all thing that we can change and override.
But that’s a story for another day.
On a side note however
There are 2 other calcview functions inside PlayerController which allow further manipulation of the camera.
CalcFirstPersonView CalcBehindView