Sega 500
1 / 73

Sega 500 - PowerPoint PPT Presentation

  • Uploaded on

Sega 500. Projecting a Crosshair. Jeff “Ezeikeil” Giles [email protected] The plan for today…. I know I promised that this week would be nearly exclusively on states, but this is just too cool to pass up.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Sega 500' - cwen

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Sega 500

Sega 500

Projecting a Crosshair

Jeff “Ezeikeil” Giles

[email protected]

The plan for today
The plan for today…

  • I know I promised that this week would be nearly exclusively on states, but this is just too cool to pass up.

  • And I get a simple demonstration of how to use states in our favour.

The plan for today1
The plan for today…

  • After having built all these 3rd person mods to UT is was quickly really apparent how difficult it is to effectively target enemy pawns in the game.

  • Not to mention the offset between the crosshair and the impact point.

The plan for today2
The plan for today…

  • Today we’re going to look at one fix possible fix to that.

  • By mapping a crosshair onto the terrain.

The plan for today3
The plan for today…

  • In effect we’re replacing the crosshair with a form of laser pointer.

  • Notice how it maps to the terrain?

The plan for today4
The plan for today…

  • …Oh…dude!...sign me up for some of that action!

  • This actually renders the game from the 3rd person quite playable and yield quite a different feel to the game.

So what s going on
So what's going on?

  • UT 2003 comes with these really neat toys called projectors which dynamically map textures on to…well…whatever you want.

  • Although you may not know it, you’ve already seen these in action…a lot.

So what s going on1
So what's going on?

  • Heh? Where?

Any shadow effect
Any Shadow effect…

There are also shadows projected from the trees, but they are hard

to see when not animating.

So what s going on2
So what's going on?

  • In effect, this tool which is placeable in the editor, maps a texture onto an object in our world. It is not ray traced.

So what s going on3
So what's going on?

  • And for moving objects, like the bulldog or our pawn, we simply bind the projector to them.

  • It’s not really a difficult process, but there are some very Specific hoops to jump through.

Getting started
Getting Started…

  • I found messing with these things finicky enough that it’s a good idea to set on up in the editor first to get an idea of what's involved.

  • So…lets do that…

A basic projector
A basic projector…

  • Once you’ve got a location set up for you projector, dig it out of the actors list and place it in the level.

  • I’m using a Dynamic projector.

A basic projector1
A basic projector…

  • Once you’ve got it in the leveland pointing in the direction you want, we need to tell it what to project and how far.

  • Yup, you guess it, time to set up some defaults…

A basic projector2
A basic projector…

  • As you can see, we have quite a list to choose from.

  • We’re only interested in 3 sections right now: ProjTexture, FOV, and FameBufferBlending.

A basic projector3
A basic projector…

  • First off, we’re going to setup the texture we intend to use which should be enough to cause something to show up…

A basic projector4
A basic projector…

  • Yup something does… A yellow box…and a black diamond on the wall…..grrrrreat.

  • Actually it IS projecting what it’s supposed to, we just have to yutz with a few more things.

A basic projector5
A basic projector…

  • Starting with the FOV…

  • The FOV defaults to 0, which is really bad since we need a positive number to define to calculate HOW to project it.

  • Any number between 0 and 100 should be good. Outside this range is going to cause weird results.

A basic projector6
A basic projector…

  • When I set mine to 10 it was is enough to get it to show up.

  • But it also caused this blue box to appear and expand the yellow one.

A basic projector7
A basic projector…

  • Looking a this blue box in the top viewport, we see that it is conical in shape…looking quite a bit like a view fustrum, wouldn’t you say?

  • Actually…Exactly like a view fustrum.

A basic projector8
A basic projector…

  • And after playing with the FameBufferBlending, we should have a working projector…

  • Mine is set to PB_Add.

A basic projector9
A basic projector…

  • And checkout what happens when we run it…

  • In 1st person it projects onto our weapon model…

A basic projector10
A basic projector…

  • And in 3rd person, it projects on any pawn or world object that happens to be in front of it.

  • Is that sweet or what!

A basic projector11
A basic projector…

  • And there you have it, a basic projector in the editor.

  • Now its time to go about binding one of these to the player.

Binding a projector to a pawn
Binding a projector to a pawn…

  • One thing to note, I’m just expanding on the mario cam ( lesson 14 ) in this example. But there’s no reason why you couldn’t adapt this to any game type…like the Max Payne cam for example.

Binding a projector to a pawn1
Binding a projector to a pawn…

  • The first thing to realize is exactly what we need to build this.

  • I followed the example used in the bulldog.

  • One Pawn, one dynamic projector.

Binding a projector to a pawn2
Binding a projector to a pawn…

  • After looking a the BulldogHeadlight projector, it’s pretty apparent that there’s not really a lot for us to do here other than set up some defaults.

  • So I just created my own class from and borrowed the defaults from the BulldogHeadlight. We’ll customize them in a moment.

Binding a projector to a pawn3
Binding a projector to a pawn…

class Target extends DynamicProjector;

function Tick(float Delta)












Binding a projector to a pawn4
Binding a projector to a pawn…









  • Pretty much straight from BulldogHeadlight, just so we have our projector to work with.

Binding a projector to a pawn5
Binding a projector to a pawn…

  • So, now’s the time to bind it to the pawn.

  • After thinking about this in terms of good OOP, seeing as all the information that we need is dependant on the the pawn class, it makes sense to create our own.

Binding a projector to a pawn6
Binding a projector to a pawn…

  • Now the creation part is easy, just derive one from xPawn, inside which we’ll create an instance of our projector.

class MarioPawn extends xPawn;

var Target crosshair;

Binding a projector to a pawn7
Binding a projector to a pawn…

  • Erm...hang on a sec.

  • How are we going to the UT to use OUR pawn and not the default xPawn class?

Binding a projector to a pawn8
Binding a projector to a pawn…

  • Well, since we’re using the old code for our mariocam.uc, we already have a custom playercontroller built and implemented for us.

  • Thus, we just tell the Playercontroller what type pawn it needs to use.

Binding a projector to a pawn9
Binding a projector to a pawn…






  • UT should now know to use our pawn…

    That wasn’t so bad now was it?

Binding a projector to a pawn10
Binding a projector to a pawn…

  • Now, we just spawn our projector into existence when the player enters the game.

function PostBeginPlay()



crosshair = spawn(class'Target', self,,location );


Binding a projector to a pawn11
Binding a projector to a pawn…

  • And as mentioned in the Projector class, we have to do a custom tick function so that it will be bound to our player.

function Tick(float deltatime)



crosshair.DetachProjector(); //order is important




Binding a projector to a pawn12
Binding a projector to a pawn…

  • And if we run it now, we get some headlights that follow use around but don’t orient with the pawn.

Ed-209: “Drop you weapon! You have 3 seconds

to comply”

Binding a projector to a pawn13
Binding a projector to a pawn…

  • This is actually easy to fix, there’s a function built into all the actors in the game called setrotation() which does just as it’s name promises.

  • Remember that we can’t do an assignment because a rotation is a constant…we HAVE to call the function.

Binding a projector to a pawn14
Binding a projector to a pawn…

  • Adding one line to our tick function in the pawn class solves that problem…

    …sort of…


Binding a projector to a pawn15
Binding a projector to a pawn…

  • It rotates with me no problem…but we don’t pitch…

“No problem Miss, I’ll get your cat

out of that tree.”

Binding a projector to a pawn16
Binding a projector to a pawn…

  • OK, so if we look back at the player controller class, we’ve made the changes to the AdjustAim function to unlock the fire axis…and it DOES work…we can shoot up.

Binding a projector to a pawn17
Binding a projector to a pawn…

  • What happened is that we grabbed the pawn rotation…which doesn’t have a pitch value.

  • The pitch value comes from the view rotation.

Binding a projector to a pawn18
Binding a projector to a pawn…

  • Right…Right… Right…I remember that now…

  • Should fix the problem!

crosshair.SetRotation( GetViewRotation()) ;

Binding a projector to a pawn19
Binding a projector to a pawn…

  • Uh…nope…same problem…

  • The Pawn class comes with a GetViewRotation function, look at how its defined…

Binding a projector to a pawn20
Binding a projector to a pawn…

  • Ok, That looks fine…getting the view rotation from the controller…lets look there.

simulated function rotator GetViewRotation()


if ( Controller == None )

return Rotation;

return Controller.GetViewRotation();


Binding a projector to a pawn21
Binding a projector to a pawn…

function rotator GetViewRotation()


return Rotation;


  • OK, this should work…what the heck?

Binding a projector to a pawn22
Binding a projector to a pawn…

  • Look back at what the pawn class asked for…the controller rotation…we are a player controller….we’re not looking in the right place yet.

  • So in Player controller…

Binding a projector to a pawn23
Binding a projector to a pawn…

function rotator GetViewRotation()


if ( bBehindView && (Pawn != None) )

return Pawn.Rotation;

return Rotation;


  • In player controller, we find that if we’re using behind view, our Pawn rotation gets returned…locking our axis up…DOH!

Binding a projector to a pawn24
Binding a projector to a pawn…

function rotator GetViewRotation()


return MarioCam(controller).Rotation;


  • To fix this, I create this guy in my pawn to get the right information.

Binding a projector to a pawn25
Binding a projector to a pawn…

  • And there we go, unlocking the axis so it now pans up and down with us.

…here kitty kitty kitty…

Customizing the projector
Customizing the projector…

  • Ok, cool.

  • Now how about making look like a crosshair so my bot looks less like ED-209.

Customizing the projector1
Customizing the projector…

  • Should be simple enough, just open up my custom projector and import a texture.

  • We’re just going to use the radar rings from the HUD in lesson 10.

Customizing the projector2
Customizing the projector…

  • So in code:

#exec texture IMPORT name=RINGS FILE=Textures\radar.bmp






  • Import our texture and set it to the projection and we should be good to go.

Customizing the projector3
Customizing the projector…

…oh my…That’s not right…

Customizing the projector4
Customizing the projector…

  • What the heck!?!?

  • All I did was change the texture!

  • This is one of those specific things that I was telling you about.

Customizing the projector5
Customizing the projector…

  • AS you can see, it’s tiling the texture…not exactly what we want.

  • We need to clamp it’s U V coordinates.

Customizing the projector6
Customizing the projector…

  • Unfortunately, it doesn’t appear that this can be done on the fly, it has to be done when the texture is imported.

  • Just add the following to the import command.


Customizing the projector7
Customizing the projector…

  • And this will solve our problem…

    Hours to find this…HOURS!!!

#exec texture IMPORT name=RINGS FILE=Textures\radar.bmp GROUP="HUD"


Customizing the projector8
Customizing the projector…

  • Note, you can also set with these parameters in the editor via the texture properties editor.

Customizing the projector9
Customizing the projector…

  • Now that we have this in the game, and there is only one of them… We have one other problem to fix.

  • A slight offset in our line of fire…the rounds go a bit high.

Customizing the projector10
Customizing the projector…

  • What’s happening here is that the rounds are being created at the players eye level which is higher than the pawns location in 3D space.

  • Remember that the pawn location is defined to be dead center his torso.

Customizing the projector11
Customizing the projector…

  • So, rooting around the pawn class some, we find a variable to solve the problem for us…gota like that. 

Customizing the projector12
Customizing the projector…

  • There’s a variable called eyeheight, which we simply add to it’s location when we spawn the projector.

local vector projheight;

projheight.z= EyeHeight;

crosshair = spawn(class'Target', self,,location+projheight, GetViewRotation() );

Customizing the projector13
Customizing the projector…

  • And the rounds go dead center…every time.

  • Just remember to update the location with this offset in the tick function.

Customizing the projector14
Customizing the projector…

  • And one last thing to fix.

  • What happens when the player dies?

  • Well, currently he keeps projecting the target rings, even when dead…which is kind of lame.

Customizing the projector15
Customizing the projector…

  • So as promised…how to make states work in our favour once again.

  • All we’re going to do here is modify state Dying so that tick does nothing and destroys the rings.

Customizing the projector16
Customizing the projector…

state Dying


function Tick(float deltatime)






Customizing the projector17
Customizing the projector…

Notice that the pawn is facing down...No rings projected

Customizing the projector18
Customizing the projector…

  • And no more rings projected when I’m dead.

End game
End Game

  • If you want to know more about projectors, there’s lost of information here for using them in the editor.

End game1
End Game

  • Well, I know I promised states this week, but that was just too cool to pass up…And we saw how to make states work for use once again…although briefly.

  • Tomorrow, we’re back to talking about states in detail. I hope the lesson and the last we’re a good way to wet your appetite for them.