Tutorial 5 Importing the Bunker

**Battlefield 2 Modding Tutorial 5**

**Importing the Bunker (WIP)**

**Set-Up:**

This tutorial assumes that you’ve followed “Battlefield 2 Modding Tutorial 3 - Custom Mod Set-Up” and created the custom mod “MyMod”. If you haven’t, you should do this now or you won’t be able to place the files in the correct places.

This tutorial also assumes that you have completed “Battlefield 2 Modding Tutorial 4 - Building The Bunker”. If you haven’t, either do this now, or alternatively you can follow the ReadMe in the “Tutorial Files” folder of tutorial 4. This is necessary because those files have to be placed correctly in order for the import to work.

If you haven’t done tutorial 4 and are just going to place the tutorial files, then after you’ve placed them in the correct places, rename “My\_Bunker\_Complete.mb” to “My\_Bunker”. (The name of the file you import is what you’re object is called, so we want to make sure this is correct now.)

The best way really is to follow the tutorials in order.

**Importing:**

We are now going to import the bunker from tutorial 4 into the editor.

* Launch the editor and select “MyMod” when the mod selection window comes up.
* Once the mod is loaded (you won’t see anything yet), select “Object Editor” from the drop-down list in the top left.
* Next choose “File>Import” from the main menu. A window will pop up labeled “Choose mesh to import..”
* Expand the “Maya” folder, and then the “My\_Bunker” folder and select “My\_Bunker.mb. Choose “OK” to load the file:

After you click “OK”, several things will happen. First, a command-line window will open and a lot of text will flow by. You will also see lines of text being printed to your output window if it’s open. Next, an error message will pop up that says “Import Generated Errors”:

<mparserWindow.jpg>

* This error message is normal. Just click “OK” to close the window.

The important thing is that once the importer has finished all this, you should see the following folder and file appear:

If this file doesn’t appear, then scroll through your output window for clues as to what may have happened. It could be something as simple as forgetting to triangulate your collision meshes, not setting up the hierarchy correctly, misnaming an important node, or not setting up the shader correctly.

* Once you have successfully imported the Bunker, drag the file from the resources list to your main window. If everything was done correctly, it should appear with textures intact.

**Note:** As I discussed in “Battlefield 2 Modding Tutorial 2 - Creating a Basic Level”, you must drag the actual file to the window, not the folder!

You should now see something like this:

<MyBunkerMainWin.jpg>

**Note**: If you don’t see the grid, you can click on the “Draw Grid” button on the right side of the editor. The camera works the same way as it does in the other sections, so you can move around and look at it.

**Testing the Bunker:**

Now that we’ve got it in the editor, we obviously want to do something with it.

* The first thing we need is a map to put it in, so switch to the Terrain Editor and create one. Use the smallest size setting of 256. Since this is just a test map, the small size will be easier to manage.
* Once you’ve created a basic terrain, just paint a small area in the middle so you can see things. You don’t have to paint the entire surface.
* Now switch to the Level editor and drag the Bunker onto your map.
* With the bunker in the map, add a control point and spawnpoint for each side:

<BunkerTestMap.jpg>

* Once you get things how you like them, choose “File>Save All” from the menu before proceeding. Sometimes the editor doesn’t like the steps we are about to take, and we don’t want to lose the work we’ve done.

Another feature of the editor is the ability to test many things without actually having to quit and launch the game. This includes the ability to run around your map without leaving the editor.

* From the menu, choose “Camera>Soldier”. After a few seconds your view should change to this:

<BunkerSoldierMode.jpg>

* At first you may discover that using the normal controls does nothing. This is another example of having to switch “focus”. Hit the spacebar once to go into control mode. (Hitting the spacebar again acts just like the game and causes you to jump. To get back to editor mode, remember to hit the escape key.)

You should now be able to run around and “test” the bunker. Most, but not all, things act the same as the actual game.

A word of caution: The editor tries to mimic the game for testing purposes, but because of the nature of the program, it can’t do everything quite as well as the game does. Because of this, you may get random crashes from doing certain things. Usually this has to do with effects, such as when firing a weapon. The editor is good as a first look at things and for doing basic testing of vehicles and so on, but for hard-core testing, you will still have to obviously launch the game itself. This is why you should always do a “Save all” just before entering this mode.

Here’s another nifty trick: You probably noticed that under “Soldier” in the camera menu, there was a listing for “Vehicle”. Here’s how you use it:

* While still in the Level Editor with your test map loaded, expand the directories in the resource bar under “bf2” until you find the jeep (or other vehicle).
* Drag the vehicle file to the map. Do not place it as a spawn point! In this case you just want to drag the file of the vehicle itself to the scene:

<BunkerJeep.jpg>

Note: This only works for testing. Once you are done you will have to delete the vehicle again because it won’t show up in the actual game unless it’s an object spawn.

* Select the vehicle and choose “Camera>Vehicle” from the menu. You can now drive around your map instead of having to run everywhere. This is especially useful for larger maps:

<BunkerJeep1P.jpg>

Note: When it first switches to vehicle mode, you may be able to drive around. You may wish to hit the spacebar again because this actually switches to control mode. Once you do this, you will be able to toggle the chase camera of the vehicle and so on and also switch positions just like in the game. Remember that like the soldier view, doing things like firing the weapons can potentially cause a crash, so be sure to do a “Save all” before switching to vehicle camera to prevent losing any of your work.

**Evaluating the Bunker:**

So now that you know the nifty tricks for testing in the editor, we need to go back and take a serious look at our Bunker.

* If you have been driving around in a vehicle, it may be tricky getting out of it again, so if you’re having problems, the easiest way is to press escape to get your cursor back, then quit and relaunch the editor. (another reason to always save first)
* Reload the test map if you’ve had to restart and switch to soldier camera as described previously.
* Run up to the bunker and look around. We want to evaluate how well the structure “works”, like if it’s tall enough, if the rooms are big enough, if the ceilings are high enough, and so on.

The first thing you’ll notice is that when trying to enter, if you’ve just placed the Bunker in the scene without adjusting it, the steps will be too high. This is because I made it so the bottom would stick through the ground a little bit to allow the terrain to slope a little. You will have to jump to get inside.

Once inside, notice that the ceilings seem a bit low. You can go back and change this if you like, but I want it to have a kind of cramped feeling.

Unlike the game where your soldier is restricted to first-person view, in the editor you can toggle through the other “vehicle” cameras by pressing “C”.  (Remember that you may have to press the space bar first to get into control mode.)

When in third-person view, I can actually see that there is a bit of room above the soldier’s head. It’s just the camera that’s giving it that cramped feeling:

<ceiling.jpg>

The last thing we need to test is the stairs. Running up the ramps, I notice that I can’t quite get up the second one. It seems that the angle is just a bit steeper than the lower one, so there are two ways you can fix this: either apply a different material to the ramp (there is probably a “stairs” material that has more friction), or just remodel a bit to change the angle of the ramp.

In this case I’m going to choose the second option and go back to my original model and remodel a bit to make the ramp less steep. Now that I’ve confirmed that the rest of the model basically “works”, I’ll also go back and add the details, like the windows and so on. I’ll cover these techniques more in a later tutorial.

You’ve now created your first staticMesh object and imported it into a map. You can now either continue with “Battlefield 2 Modding Tutorial 6 - Building the Car” or skip ahead to “Battlefield 2 Modding Tutorial 8 – Refining the Bunker”.