UnrealScript Game Programming Cookbook

(Chris Devlin) #1

Scripting a Camera System


72

Creating a third person camera


UDK now comes with a third person camera built into the kit, but we'd still prefer to use our
own modular camera system. Epic's popular Gears of War franchise uses this camera style,
and then zooms into an over-the-shoulder view when sprinting. We'll cover more of that in
our next recipe.


Getting ready


As with our previous recipe, we'll require one similar change in the
TutorialPlayerCotroller class. Under defaultproperties,
we'll need to change it so that it reads as the following:


CameraClass = Class'ThirdPersonCam'

Our code looks nearly identical to that of our first person camera, minus a few simple changes
that I'll highlight. Most notably, we're looking to hide our first person mesh, so that only our
third person mesh is exposed to the camera.


In the end, you may notice that your projectiles are not firing from the correct mesh. Not to
worry, this isn't an issue with the camera, but a simple change that we need to make in the
weapon class, which we'll highlight in the chapter about weapons.


If your game is using our Tut_Pawn, Tutorial_ShockWeapon, and TutAttachment
Shockweapon classes, then you'll be fine, and you can see the exact functions that allow
our projectiles to fire from the proper location.


How to do it...


Rather than rely on the values we've entered in our archetype, our camera will now be built
around hardcoded numbers which we've deemed to best suit our needs, just as we did with
the first person camera. For this recipe we'll be creating a new class for our third person
camera, and then binding it to our player controller:



  1. Create a new class called ThirdPersonCam and have it extend from the
    Camera class:
    class ThirdPersonCam extends Camera

Free download pdf