Sega 500
description
Transcript of Sega 500
![Page 2: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/2.jpg)
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
![Page 3: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/3.jpg)
Today
We’re going to take our first steps towards fixing that.
We’re going to break the camera away from the player.
![Page 4: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/4.jpg)
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”
![Page 5: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/5.jpg)
Behind view
![Page 6: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/6.jpg)
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.
![Page 7: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/7.jpg)
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.
![Page 8: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/8.jpg)
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.
![Page 9: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/9.jpg)
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.
![Page 10: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/10.jpg)
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.
![Page 11: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/11.jpg)
Behind view
Then, lets override the PostRender function and set bBehindview to true.
To the code…
![Page 12: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/12.jpg)
Behind view
Hang-on! I don’t seem to have access via the controller.
![Page 13: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/13.jpg)
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.
![Page 14: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/14.jpg)
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…
![Page 15: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/15.jpg)
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 );
![Page 16: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/16.jpg)
Behind view
It simply returns true if this actor belongs to a named class.
Hey! Handy!
So how do we use it…
![Page 17: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/17.jpg)
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;}
![Page 18: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/18.jpg)
Behind view
![Page 19: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/19.jpg)
What are controllers?
Well, that’s kind of neat…
So what then are controllers?
![Page 20: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/20.jpg)
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().
![Page 21: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/21.jpg)
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.
![Page 22: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/22.jpg)
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.
![Page 23: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/23.jpg)
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
![Page 24: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/24.jpg)
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;
![Page 25: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/25.jpg)
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:
![Page 26: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/26.jpg)
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.
![Page 27: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/27.jpg)
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.
![Page 28: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/28.jpg)
Behind view
Making some changes, we can condense our code to
function PostRender(canvas c)
{
super.PostRender(c);
playerowner.BehindView(true);
}
![Page 29: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/29.jpg)
Behind view
And, it works!....yay me!
![Page 30: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/30.jpg)
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.
![Page 31: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/31.jpg)
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.
![Page 32: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/32.jpg)
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;}
![Page 33: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/33.jpg)
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.
![Page 34: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/34.jpg)
Custom Controllers
![Page 35: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/35.jpg)
Custom Controllers
What, I’m dead?
And I can’t respawn?
Ok…What’s going on…
![Page 36: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/36.jpg)
Custom Controllers
Look closer at the class tree.
We derived of Playercontroller
![Page 37: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/37.jpg)
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
![Page 38: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/38.jpg)
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?”
![Page 39: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/39.jpg)
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".
![Page 40: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/40.jpg)
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.
![Page 41: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/41.jpg)
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;}
![Page 42: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/42.jpg)
Custom Controllers
Looks like it works…
But what’s all this boxy stuff?
Try moving…see what happens.
![Page 43: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/43.jpg)
Custom Controllers
GAH!
My body’s running away!
That’s moderately disturbing.
![Page 44: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/44.jpg)
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;}
![Page 45: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/45.jpg)
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.
![Page 46: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/46.jpg)
Custom Controllers
Notice that the screen flickers but instantly snaps back to the chase cam.
![Page 47: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/47.jpg)
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.
![Page 48: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/48.jpg)
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.
![Page 49: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/49.jpg)
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}
![Page 50: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/50.jpg)
Custom Controllers
Notice how the camera tracks me from my start point…keeping me dead center I the screen.
![Page 51: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/51.jpg)
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.
![Page 52: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/52.jpg)
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.
![Page 53: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/53.jpg)
Custom Controllers
However these are all thing that we can change and override.
But that’s a story for another day.
![Page 54: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/54.jpg)
On a side note however
There are 2 other calcview functions inside PlayerController which allow further manipulation of the camera.
CalcFirstPersonView CalcBehindView
![Page 55: Sega 500](https://reader036.fdocuments.net/reader036/viewer/2022070409/56814462550346895db0f6da/html5/thumbnails/55.jpg)
Next time
We’ll carry on with our manipulations of the camera system and see what other funkiness we can squeeze out of it.