apply-We're going to make a few weapons, and in order to maintain balance, we'll make thing that can be used in game to counteract the effects of these weapons.. Trees If Joyce Kilmer ha
Trang 1the midline of the tire are aligned withthe origin bug.
Testing Your Runabout
In order to test the runabout, we firstneed to export it from MilkShape
1 After saving your work, chooseFile, Export, Torque Game EngineDTS You will see the Torque GameEngine (DTS) Exporter dialog boxappear
2 Use defaults, but make sure theyare correct
You want to have Export animationand Export material informationselected, and Collision Mesh should
be set to Collision Meshes (this isautomatic if the exporter finds amesh whose name starts with "Col-lision") Click OK when ready
3 Export your runabout to DTS format as C:\3DGPAi1\racing\
1 Locate the file C:\3DGPAi1\racing\server\scripts\car.cs and open it with UltraEdit
2 There are two lines that say this:
Figure 15.32 Seat mounts.
Figure 15.33 Collision mesh.
Trang 2And replace it with this line:
shapeFile = "~/data/shapes/car/wheel.dts";
4 Save the file
Okay, now it's time to run the racing demo The following may look familiar to you, since
we did this back in Chapter 9
1 Browse to C:\3DGPAi1 and click the Run racing Demo shortcut
2 Click Start Mission
3 In the Launch dialog box, make sure that the Multiplayer Mission box is cleared
4 Select Car Race Track from the mission list
5 Click Launch
6 After the game loads, have at it! You probably should switch to Chase view bypressing the Tab key—there's more to see See Table 15.1 for the keyboard controls
Moving Right Along
Building the model is only half the battle—well, maybe three-quarters There is still the ter of defining the vehicle's characteristics, like mass, drag, speeds, particle generators, colli-sion handlers, and so on You take care of these things in scripts that run on the server
mat-To do the testing you just did, you used the existing demo buggy script that comes withthe Torque Engine and simply substituted our model in place of the dune buggy It lookslike a roadster but drives like a dune buggy! In fact you will recall that you had a test-drive
of a dune buggy back in Chapter 9
Later, in Chapter 22, we will create the script that will define the behavior of the vehiclethat we've modeled here and its response to user inputs and game environment stimuli.Coming up next in Chapter 16, we'll continue with MilkShape and make some weaponsand other items
Table 15.1 Torque Racing Demo Controls
mouse steering left or right
Up Arrow accelerate Down Arrow brake Tab toggle from first- to third-person viewpoint Escape exit the game
Trang 3Making Weapons and Items
In this chapter we're going to make a bunch of things Most of the techniques used will
basically be a review for you, so you can see this chapter as one big exercise in ing what you've learned to different situations
apply-We're going to make a few weapons, and in order to maintain balance, we'll make thing that can be used in game to counteract the effects of these weapons
some-We'll also make some items that one might call decorations for the game The purpose of
these items—some trees and a rock—is to provide some clutter This is to help fill out erwise sterile-looking game worlds, making them more interesting to wander around in
oth-The Health Kit
We'll start out with an easy one Like I said, this will be a basic review, but it's important
to go over the process involved in creating an item for use in the game so that the broadsteps become obvious and second nature
The Model
The Health Kit is little more than a fancy-looking box, as you can see from Figure 16.1 Sothis won't take long
1 Fire up MilkShape and create an empty document
2 Use the Box tool to create a box, as shown in Figure 16.2
3 Align the box to be centered at the origin for all three axes, as you can see in Figure16.2
Trang 44 On the Materials tab, create anew material, using
C:\3DGPAi1\RESOURCES\CH16
\ healthkit.png as the bitmap
5 Name the material "healthkit"
6 Select the box and assign thehealthkit material to it
7 Make sure that the 3D view hasbeen set to texture mode Youshould see a nice, shiny new first-aid kit kind of item there, likethat in Figure 16.3 This onealways has bandages in it!
8 Save your work
9 After saving your work, chooseFile, Export, Torque GameEngine DTS You will see theTorque Game Engine (DTS)Exporter appear
10 You want to take the defaults buthave Collision Mesh set to None
11 Export the box to C:\3DGPAi1\fps\data\shapes\items\healthk-its.dts Click Yes if you get analert asking if you want toreplace an existing file with thatname
Testing the Health Kit
To use the Health Kit in game, youmerely have to run over it to pick it up.Then you activate it by pressing the "h"key to restore your health whenever itgets too low You may remember using
a kind of first-aid kit in one of yoursample games from an earlier chap-ter—Emaga5—where you got healthback just by running over the first-aidkit, or Health Kit This one you have to
Figure 16.1 The Health Kit in game.
Figure 16.2 The box.
Figure 16.3 The Health Kit model.
Trang 5pick up and activate; we'll test that functionality later when we get back into server scripts.
Right now we just want to see our fine creation in the game world
1 Browse to C:\3DGPAi1 and click the Run fps Demo shortcut
2 Click Start Mission
3 In the Launch dialog box, make sure that the Multiplayer Mission box is cleared
4 Select Water World from the mission list
Oh, big deal, a rock—what's up with
that, you ask? Well, it is going to be
your own handmade rock! Thatshould be worth something
The point here is that, even though therock is not much more complex than
the Health Kit, it is somewhat more
complex nonetheless It does less for
us in the game, but it is one of thosedecoration-type items I mentioned—
and stuff like this, while unglamorous,can greatly contribute to the ambience
Figure 16.4 Locating the big gray block.
Figure 16.5 The rock in game.
Trang 6in a horizontal flat plane, as shown inFigure 16.7 Already it's starting to looklike a rock.
5 Still in the Side view, drag the verticesaround on the left side until you getsomething resembling Figure 16.8
6 Now in the Top view, drag some morevertices around until you get somethingresembling Figure 16.9 It's almost a rocknow!
7 On the Materials tab, create a new rial, using C:\3DGPAi1\RESOURCES\CH16\rock.png as the bitmap
mate-8 Name the material "rock"
9 Select the entire rock model and assignthe rock material to it
10 Make sure that the 3D view has been set
to texture mode You should see a nicelumpy and ancient-looking rock there,like that in Figure 16.10
11 Save your work
12 After saving your work, choose File,Export, Torque Game Engine DTS
Figure 16.6 The sphere.
Figure 16.7 The truncated sphere.
Figure 16.8 The stretched rock-sphere Figure 16.9 The almost rock.
Trang 713 You want to take all the defaults(Collision Mesh should be set toBounding Box).
14 Export the box to C:\3DGPAi1\fps\data\
shapes\organic\rock1.dts ClickYes if you get an alert asking ifyou want to replace an existingfile with that name
Testing the Rock
The rock has a bounding box set forcollision because it is, after all, arock—you can't go through it
1 Browse to C:\3DGPAi1 and click the Run fps Demo shortcut
2 Click Start Mission
3 In the Launch dialog box, make sure that the Multiplayer Mission box is cleared
4 Select Water World from the mission list
5 Click Launch
6 After the game loads, look around for your rock jutting out from a saddle betweentwo hills into the water Figure 16.11 shows what the rock (marked by the arrow)looks like
7 Run over to the rock On top of it you will find the Health Kit
8 Run over the kit to automatically pick it up You will see a message in your chatwindow telling you that you've
picked it up
Trees
If Joyce Kilmer had been a game oper, he might have written, "I thinkthat I shall never see, a model so annoy-ing as a tree." Or something like that
devel-But he didn't, so that's too bad Reallytalented game developer poets are rare
Nonetheless, computer model trees
really are annoying There is this
Figure 16.10 The rock model.
Figure 16.11 Locating the rock.
Trang 8conundrum: If you can interact reasonably well with a model tree, then it looks awful Ifthe tree looks really good, then interacting with it is awful.
The problem is twofold We see them everywhere, in most parts of the world, so they vide a great deal of the background to our daily lives This means that in virtual worlds, if
pro-there are no trees in the background, we just know something's wrong even if we can't quite
put our finger on the problem They are ubiquitous And that means we also have a highlydeveloped subconscious sense of what they should look like, when we aren't…um…actually looking at them With me so far? Okay, that's problem number one
The other problem is that they are so dad-blamed complex! Even a sapling has lots of tle branches and twigs and leaves and buds and stuff If you have a polygon budget (and
lit-if you are making games, you have a polygon budget!), then these suckers will dry up that
account faster than a barking moonbat can change its mind
So, on the one hand, to have convincing trees that satiate the subconscious gamer's mind,
we need to be attentive to details And on the other hand, those very details can drag ourframe rates lower than a snake's belly in a wheel rut
To interact well with a tree means several things: When you approach it, circle it, look upinto its branches and leaves, you see things properly in three-dimensional perspective Youcan collide with the thicker parts like the trunk and the big lower branches, but if you fellonto a tree from above, you would likely fall a long way down through the airy upperstructures before you stopped
But unless you want to put 30,000 polygon trees into your game world, you'll have to promise on all those fiddly details There are ways to strip off a few thousand polygonshere and there, but long before you get anywhere reasonable, your compromises startmaking the tree much less treelike So then you have to pass a few edicts like this:
com-From this point hence, this tree, and all other trees like this tree that grace our fair land, may only be viewed from certain angles—all of the aforementioned angles being from a level on the ground to a level not exceeding the height that one man can jump.
But then you start to drain the flexibility out of your game world What if you are ing on the back of a truck? Or on a nearby hill? Or flying overhead in an ornithopter? Well,you can't do any of those things if you really want to save the trees!
stand-And don't even talk to me about having forests of these things in a game Though thereare ways to make trees look absolutely stunning from a distance, and only take two poly-
gons to accomplish the task! Using a technique called billboarding we can create trees that
look great from any angle as long we are at least moderately far from the tree—say a ple dozen meters or more But up close they are nothing but flat planes that turn to alwaysface you You can't look up into them from below and search for robin's nests You can'tclimb them And you certainly can't fall into them from above! I mean, what fun is that?
Trang 9cou-So why all the blather, you ask? Well, I'll tell you We're going to look at modeling somegame-friendly trees in this section, and I want you to enter into this prepared, under-standing why I'm going to show you two different ways to model a tree There are otherways, but the two represent the opposite extremes First, we'll create a "normal" low-poly-
gon solid tree with a collision mesh One that you could potentially climb using
appropri-ate program code One that you could actually get beneath and peer up into It won't look
all that great, but it will look like a tree After that, we'll create a billboard tree that can be
used to make vast forests of trees that will actually look like forests
The Solid Tree
The solid tree is constructed of 3D object primitives, mostly cylinders that join end to endand taper The one we'll make won't have any leaves—it's a generic big backyard tree inthe winter
I should warn you now that we aren't going to build a megapolygon old oak tree or thing like that here Instead, we're going to do just enough so you'll have a good idea whereyou can go with the model and what's involved with this approach
any-Having said all that, go ahead and create a new empty document in MilkShape, and let'sget crackin'
1 Select the Cylinder tool and set it to 4 stacks and 12 slices in the parameter boxes
2 Click your cursor in the Side view, and drag down and to the right to create acylinder like the one shown in Figure 16.12
3 Still in the Side view, select the vertices in the second row from the bottom, andthen use the Move tool to shift them to one side
4 Switch to the Top view and do thesame thing, moving the vertices slightlyaway from being aligned with the cen-ter of the cylinder
5 Repeat steps 3 and 4 with the next tworows of vertices going up, one row at atime, using Figure 16.13 as a guide
6 Do an incremental scaling workingfrom the second row of vertices going
up, so that you get a tapered trunk, likethat shown in Figure 16.14
7 Use the Duplicate function to make acopy of the trunk Figure 16.12 Four-stack cylinder.
Trang 10It will look like nothing happened, but a copy wasmade in place Select the Move tool and then dragthe selected object to a clear area There you go—you will have the copy, and the original object willhave been left behind.
8 Move the copy to one side Thenscale it and rotate it so that youget something that looks like Figure 16.15
9 Drag the branch over to thetrunk and place it with thelarger end inside the bounds ofthe trunk
10 Make more copies of the branch,scaling, rotating, and tweakingthem as desired, until you getsomething like the model shown
12 Name the material "bark"
13 Select the trunk using the Groups tab,and assign the bark material to it
14 Assign the bark material to each of thebranches Do not select them all at onceand assign the material—instead, dothem one at a time
Figure 16.13 Crooked cylinder.
Figure 16.15 Branching out.
Figure 16.14 Crooked cylinder becomes a tree trunk.
Trang 1115 Make sure that the 3D view hasbeen set to texture mode Youshould see the textured treethere, like that in Figure 16.17.
Okay, we'll stop there Ofcourse, we could go on and on,making it more detailed, andthat's certainly something Iencourage you to do It's justpointlessly repetitive to do itright now Let's move along andadd a collision mesh
16 Create a box and position it asshown in Figure 16.18
17 Rename the box, calling it "Collision"
18 Save your work
19 After saving your work, choose File,Export, Torque Game Engine DTS
20 You want to take all the defaults sion Mesh should set to BoundingBox)
(Colli-21 Export the box to C:\3DGPAi1\
fps\data\shapes\organic\tree1.dts ClickYes if you get an alert asking if youwant to replace an existing file withthat name
Testing the Solid Tree
The solid tree has a collision mesh—
you can't go through it You also can'tclimb it as is (you could if you wrotethe appropriate script code) Anyway,
to test out our solid tree, do the lowing:
fol-1 Browse to C:\3DGPAi1 and clickthe Run fps Demo shortcut
2 Click Start Mission
Figure 16.16 Adding more branches.
Figure 16.18 The tree collision mesh.
Figure 16.17 The textured tree.
Trang 123 In the Launch dialog box, make sure that the Multiplayer Mission box is cleared.
4 Select Water World from the mission list
5 Click Launch
6 After the game loads, look around for your tree poking up from a hill behind thatblock where you found the Health Kit
7 Run over to the tree and admire your handiwork
8 Try to run through the tree If you hurt your head, you know where the first-aidkit is!
The Billboard Tree
The billboard tree is the Ferrari of game trees It looks good and is so low on polygons that
if you remove one polygon, it vanishes! But it is specialized and you can't do much with it.Create a new empty document in MilkShape
1 Select the Vertex tool and place three vertices in an equilateral triangle formation
2 Use the Face tool and create a face, as shown in Figure 16.19
3 On the Materials tab, create a new material, usingC:\3DGPAi1\RESOURCES\CH16\spruce.jpg as the bitmap
n o t e
There is a quirk in MilkShape when using bitmaps that have alpha channels in them Because ofthis, when we make a model that uses a texture with an alpha channel, like the billboard tree, weneed to make another version of the texture without the alpha channel, but with the same name(not including extension) So although in the game we will use the spruce.png texture file, we need
to use spruce.jpg in the MilkShape model material
4 Name the material "spruce: Trans".The ": Trans" part tells the exporterthat the alpha channel for thismaterial should be set to translu-cent mode
5 With the new material selected,move the right-hand slider to themiddle position This will tell theexporter to enable alpha trans-parency for this material
Figure 16.19 The tree triangle.
Trang 136 Select the triangle using the Groups tab, and assign the spruce material to it.
7 Make sure that the 3D view has been set to Texture mode You should see the tured tree there, as shown in Figure 16.20
tex-8 Rename the triangle in the Groups tab as "firstface: BillboardZ" This identifies thepolygon as a billboard-z type
9 Create a special material This is a material that tells the exporter how to do certain
things The directive is embedded in the name—in this case call the material
"opt:size=100" There is nothing else needed for the material This directive tellsthe exporter to scale the object up by 100 times
n o t e
Abillboard is a single polygon object with a texture that always faces toward the player in thegame Some kinds of billboards only face the player horizontally If you get above them, they don'tface up These are called billboard-z
10 Save your work
11 After saving your work, choose File, Export, Torque Game Engine DTS
12 You want to take all the defaults (Collision Mesh should be set to None)
13 Export the box to C:\3DGPAi1\fps\data\shapes\organic\tree2.dts Click Yes if youget an alert asking if you want to replace an existing file with that name
Testing the Billboard Tree
The billboard tree has no collision mesh—you can't bump the tree but instead you just goright through it You also can't climb it, though you probably wouldn't want to
1 Browse to C:\3DGPAi1 and click the Run fps Demo shortcut
2 Click Start Mission
3 In the Launch dialog box, makesure that the Multiplayer Mis-sion box is cleared
4 Select Water World from themission list
5 Click Launch
6 After the game loads, your tree
is actually a group of trees ing up from a hill behind thatblock where you found theHealth Kit
Trang 14pok-7 Run over to the trees and take a look.
8 Try to run through any of the trees If you hurt your head, go back and check yourmodel! You may have inadvertently left a collision mesh in it
As you can see, the billboard tree is kind to your video card and will keep your frame ratesright up there In fact, you can build forests of these things and only have as many poly-gons as one of the solid trees!
The Tommy Gun
The famous Thompson submachine gun is a somewhat obsolete weapon that most ple are familiar with visually, even if they don't know what it's called
peo-The technique we will use is the Extrusion method When it comes to modeling weapons,Extrusion is probably the method of choice for the simple reason that it often works wellwhen using photographs for source material There are dozens and dozens of books andmany Internet resources available that have photographs and technical drawings ofweapons, but remember that much of the source material is copyrighted
For our Tommy gun, I'll work from a sketch I made, shown in Figure 16.21
t i p
To create your weapons, you can use a photograph or detailed diagram of your own if you like, ever, you are perfectly free to use my sketches and artwork in any way you want to The choice isyours
how-The sketch is rough and not very detailed, but it will do just fine for our purposes Thismodel will have as few polygons in it as I think we can get away with I've made two ver-sions of it for you to use: one for the skin and one to act as the extrusion reference image
Making the Model
Get MilkShape running and warming up in the driveway, and we'll get started in a minute
We will use C:\3DGPAi1\RESOURCES\CH16\tommygun.png as the texture forthe Tommy gun's skin You can find theextrusion guide sketch at C:\3DGPAi1\RESOURCES\CH16\tommygun_ref.bmp.You need to set the latter as the back-ground image for the Side view window inMilkShape; we'll use the former later inthis section
Figure 16.21 Tommy gun sketch.
Trang 151 Select the Vertex tool, making sure thatthe Auto Tool check box is cleared.
2 In the Side view, start placing vertices
at all the major corners and pointsaround the components of the gun SeeFigure 16.22 for reference
3 Start making faces No! I meant in themodel, not at me! You will probablyhave to zoom in some to get enoughseparation between the vertices
Be careful as you move along, makingsure you get all the faces For tips andother information on faces, check back
to Chapter 15 Figure 16.23 shows thefinished polygon faces around the muz-zle, which can be a bit fiddly Noticehow far I zoomed in
Figure 16.24 shows the barrel and stock faces A warning about the barrel
fore-is in order here, I think In thfore-is model
we will stick with a straight extrusionexercise—but I highly recommend thatafter you complete this section yourework the model and make the barrel acylinder object The results will be nicer
Figure 16.22 Tommy gun vertices.
Figure 16.23 Tommy gun muzzle faces.
Figure 16.24 Tommy gun barrel and Figure 16.25 Tommy gun metal body faces.