You are on page 1of 9

How to Make an FPS in Unity 3D

By: Ama291 a.k.a. Alexanderrockandroll


Difficulty: Easy, NO Javascript knowledge needed.

Time: 1-2 Hours

Materials: 1) 2) 3) 4) 5) 6) Computer with 1+ GB of RAM (Mac OS X or PC) Unity 3D Unity FPS Tutorial project assets Time Storyline External Mouse

Contents:
Prerequisites..2 Starting Up..2 Creating Your Scene..2 Creating Your Player and Weapons4 Creating Ragdolls and AI.8

Prerequisites
You can download Unity 3D from: http://unity3d.com/unity/download/. You will also need the Unity FPS Tutorial Completed folder, which can be found at: http://unity3d.com/support/resources/tutorials/fpstutorial.html. I would recommend getting an external mouse, because scrolling with the trackpad is very difficult and imprecise. Optional: You can download the Island Demo because of its valuable assets at: http://unity3d.com/support/resources/exampleprojects/islanddemo.

Starting Up
Open Unity 3D, and load the FPS Tutorial Completed project, by pressing File-Open Project-Open Other, and then selecting the folder you downloaded. Then press Window-Layouts-2 by 3. This allows you to view the scene on the top left and the game view under it.

Creating Your Scene


Create Your Terrain: Create the terrain by pressing Terrain-Create Terrain. The terrain is huge, so I would recommend resizing it. You can do so by pressing Terrain-Set Resolution, and then editing the terrain width and length.

Texture: you can set the terrain texture, and in this tutorial the terrain will be a grassland. Click on the Terrain object in the Hierarchy tab. In the Inspector tab, click on the paint brush, and then click Edit Textures-Add Texture. Then click on the little circle on the right of the Splat column. For this tutorial, we will select the Grass (Hill) texture and press add. Mountains & Hills: To create mountains and hills, simply click on the Terrain object, and then the icon with hills and an upward arrow. Choose your brush and brush size, and then you can simply draw mountains on the terrain. Lights: To add light to the terrain simply press GameObject-Create OtherPoint Light. Click on the Point light object and adjust the range until the light is visible. Sky: To add a sky, Unity has what are called skyboxes, which are images of real skies. Search for Blue_sky in the project tab, and this is the skybox we will use. Now press Edit-Render settings, and drag the Blue_sky from the project tab into None (Material) in the Skybox Material column. Trees: Click on the Terrain object, and then click on the tree icon. Press Edit Trees-Add Tree, and in the tree column, press the little circle. Choose Palm and then press Add. You can now adjust the brush and draw trees.

Grass: Click on the Terrain object, and then click on the flowers icon. Press Edit Details-Add Grass Texture, and click on the little circle in the Detail Texture column. Choose the grass texture, adjust the colors, and press Add. You can now adjust the brush and draw grass. Water: You can download TechzoneTVs water prefab from: http://www.mediafire.com/?gynd0nqzzzh. Just drag it from its location into the Project tab. You can place water on the map by dragging the Island Water prefab into the Scene view.

Creating Your Player and Weapons


Player: To create your player, select Standard Assets-Prefabs-First Person Controller, and drag the prefab into the scene view. Make sure that your character is above the ground, or it will fall through the map. If you press the play button, you can now play your game in the game view. You should be able to move using the Arrow Keys or WASD, jump with Space and look in all directions with the mouse. You can now delete the main camera object that is not under the First Person Controller. To give the player health, go to WeaponScripts, and drag the CharacterDamage script onto the First Person Controller. To make a die

sound, go to Sounds and drag playerDie as the variable for Die Sound on the First Person Controller. Weapons Group: Create an empty game object and name it WeaponsGroup. Drag that onto the Main Camera object which is found under the First Person Controller in the Hierarchy View. Go to WeaponScripts, and drag the PlayerWeapons script onto the WeaponsGroup game object. This will allow you to switch between the Machine Gun and Rocket Launcher that we will create. Machine Gun: To create your Machine Gun, create a new empty game object and name it MachineGun. Now go to Objects-Weapons, and drag the machineGun object into the Scene view and make sure it is in the spot you want on the game view, and it is visible to the camera. Now drag the machineGun object in the Hierarchy view onto the MachineGun empty game object, and drag the MachineGun empty game object onto the WeaponsGroup. Now go to WeaponScripts and drag the MachineGun script onto the machineGun object, not the empty game object. Now adjust the reloadTime so it is 2 seconds, to make a more realistic reload time. For the muzzleFlash variable, drag the muzzleFlash object under the machineGun object there. If you press the play button, you should be able to shoot by clicking the mouse button. Next, we will add the sparks

that appear when a bullet hits the ground. Go to Standard Assets-Particles, and drag the Sparks object onto the machineGun object. Then you need to add some sound to make the game interesting, so go to Sounds and drag machineGunSingleShotLoop onto the machineGun object. Now if you press play, when you fire, there should be sparks where the bullet hits the ground and shooting noises. Rocket Launcher: Create a new empty game object called RLauncher, and drag it onto the WeaponsGroup empty game object. Now go to Objects-Weapons, and drag the rocketLauncher object into the scene view and put it in the same position as your Machine Gun. Drag the rocketLauncher object in the Hierarchy view onto the RLauncher empty game object. To make the launcher work, go to WeaponScripts and add the MachineGun and RocketLauncher scripts to the rocketLauncher object. Make sure that the bullets per clip on the MachineGun script is the same as the ammo on the RocketLauncher script, and set the reload time to an extremely high number such as; 1,000,000,000,000. Also mod the damage of the MachineGun script to a number over 100, you want the Rocket Launcher to be a 1 shot kill. Now, we are going to make the ammo for the Rocket Launcher. Go to Objects-Weapons and drag the rocket object onto the scene view. Now click on the rocket and press Component-Physics-Box Collider. Then

press GameObject-Create Other-Particle System. Now drag the particle system behind the rocket and adjust it to your liking. In the Hierarchy view, drag the particle system onto the rocket object. Now press Create-Prefab and rename the prefab to Rocket1, and drag the rocket object from the Hierarchy view onto the Rocket1 prefab. You can delete the rocket object in the hierarchy view, and then click on Rocket1 and press Component-Physics-Rigidbody, and uncheck use gravity. Also, go to WeaponScripts and drag the Rocket script onto Rocket1. Now click on the rocketLauncher object and drag the Rocket1 prefab under the variable for Projectile. Click on Rocket1 and press Component-Physics-Box Collider. If you press play, you should be able to shoot a rocket. We can add an explosion by going to Standard Assets-Particles and renaming the Small Explosion to Smexplosion. Drag Smexplosion into the explosion variable on Rocket1. Now we can make a new javascript called explosion and adding the following script:

var SmexplosionTime = 1.0; function Start() { Destroy( gameObject, SmexplosionTime ); }

Drag this javascript onto Smexplosion object and now when the rocket hits an object, it should explode. Now to add some sound, go to Sounds and drag RocketLauncherFire onto the Rocket1 prefab and RocketLauncherImpact onto the Smexplosion object.

Creating Ragdolls and AI


Ragdoll: To create a Ragdoll (Dead AI) and go to Robot Artwork and drag the robot object into the scene view. Now press Game Object-Create OtherRagdoll, and assign the parts. Hips is upleg, Knee is lowleg, Root is roothandle, Foot is heel, Arm is uparm, Elbow is lowarm, middle spine is spine2, and head is head. Click on the gun object under the robot and press Component-PhysicsRigidbody and make sure use gravity is checked. Now create a new prefab and name it Ragdoll, and drag the robot from the Hierarchy view onto the Ragdoll prefab. Waypoint: Create a new game object and name it Waypoint, and go to WeaponScripts and drag the AutoWayPoint script onto the Waypoint empty game object. Create a new prefab and name it Waypoint, and drag the Waypoint empty game object onto it, and then delete the Waypoint empty game object. Drag

three Waypoints into the scene view in a triangle. Make sure the Y position is 1 for each of them. AI: To create an AI, go to Robot Artwork and drag the robot into the scene view, in the middle of the three waypoints. Make sure the robot is above the ground so it doesnt fall through the map. Now go to WeaponScripts and drag AI, AIAnimation, and CharacterDamage onto the robot. Create a new empty game object, and call it gun2. Make a new empty game object called RoboRocket. Now go to WeaponScripts and drag the RocketLauncher and MachineGun scripts onto the RoboRocket game object. Set the projectile of the RocketLauncher script as the Rocket1 prefab. Modify the damage of the Machinegun script to the value of your choice, but just remember that the player has only 100 health. Now drag the RoboRocket empty game object onto the robot. Now create a new prefab called AI and drag the robot from the hierarchy view onto that prefab, and then you can delete the robot from the hierarchy view. Note: When you put down AI, they must be in the middle of a triangle of Waypoints. Every time you add a robot, you need to drag First Person Controller as the target, the Ragdoll as the Die Replacement, and then go to Sounds and drag the monsterScream as the Die sound. Also, you are going to need to position the RoboRocket so it shoots rockets in the correct direction.

You might also like