Chapter 5. Build a Rocket Launcher!

In this chapter, we will learn how to create a rocket launcher. Here, we will first use the FPS camera and controller from the Unity built-in FPS package, but we will tweak our camera view to see from the character's shoulder as in Resident Evil 4 or 5. We will also take the character model and animation from the FPS tutorial package from Unity, which we can download from the following website:

http://unity3d.com/support/resources/tutorials/fpstutorial.html.

Then, we will adapt the built-in FPS controller script to be able to play the animation of the character, and make the controller similar to the Resident Evil style controller. Next, we will create a rocket prefab and the rocket launcher script to fire our rocket, which will also include the use of the built-in fire explosion particle and custom smoke particle effect from the launcher when we fire.

Mission briefing

We will create a character that carries a rocket launcher and is able to shoot it as well as creating the camera view looking back from the character shoulder (third-person camera view). Then, we will add the character controller script to control our character, and the player will have to hold the Aim button to be able to shoot the rocket, similar to the Resident Evil 4 or 5 styles.

What does it do?

We will start with applying the built-in CharacterMotor , FPSInputController , and MouseLook scripts from the built-in FPS character controller. Then, we will add the character model and start creating a new script by adapting part of the code in the FPSInputController script. Then, we will be able to control the animation for our character to shoot, walk, run, and remain idle.

Next, we will create a rocket prefab and the rocket launcher script to fire our rocket. We will use and adapt the built-in explosion and fire trial particle in Unity, and attach them to our rocket prefab. We will also create a new smoke particle, which will appear from the barrel of the rocket launcher when the player clicks Shoot.

Then, we will create the scope target for aiming. We will also create the launcher and smoke GameObject, which are the start position of the rocket and the smoke particle.

Finally, we will add the rocket GUITexture object and script to track the number of bullets we have left, after each shot. We will also add the Reload button to refill our bullet when the character is out of the bullet.

Why Is It Awesome?

When we complete this chapter, we will be able to create the third-person shooter style camera view and controller, which is very popular in many games today. We will also be able to create a rocket launcher weapon and particle by using the prefab technique. Finally, we will be able to create an outline text with the GUITexture object for tracking the number of bullets left.

Your Hotshot Objectives

In the last chapter, we already talked about how to create a third-person controller script to control our character. In this chapter, we will use a similar concept and combine it with the built-in first-person controller prefab style to create our third-person shooter script to fire a rocket from the rocket launcher. Here is what we will do:

  • Setting up the character with the first-person controller prefab
  • Creating the New3PSController and MouseLook_JS scripts
  • Create a rocket launcher and a scope target
  • Create the rockets and particles
  • Create the rocket bullet UI

Mission Checklist

First, we need the chapter 5 project package, which will include the character model with a gun from the Unity FPS tutorial website, and all the necessary assets for this chapter.

So, let's browse to http://www.packtpub.com/support?nid=8267 and download Chapter5.zip package. Unzip it and we will see Chapter5.unitypackage, and we are ready.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.37.12