Chapter 4. Add Character Control and Animation to our Hero/Heroine

Here we are in part two of Hero/Heroine. In this chapter, we will make our character come to life by using the animation script to control our character to walk, jump, and run with smooth transition from one animation to another.

We will learn how to set up the animation clip for our imported 3D model, understanding the concept of a built-in third-person controller, and creating a custom third-person controller and camera, which is similar to the built-in third-person controller script. This way we will obtain a good understanding of the built-in script and can adapt it to use for the specific extra controller or animation later on.

Mission briefing

We will create a basic custom third-person controller and third-person camera script to control our character's animation. This will allow us to control our character similar to the Hack and Slash style game, such as the Devil May Cry series, Gods of Wars, Tomb Raider, and so on.

What does it do?

In this chapter, we will start with setting up the animation clip from the imported FBX model with animation (walk, run, jump, and fall), which is created from other 3D software.

Next, we will add the Physics Character Controller component instead of the Physics Rigidbody. This Character Controller will give us the ability to access collision detection as the well as Move() function, which is very easy to use.

Note

We will use the Move() function to move our character while playing the animation. This function can be accessed from the CharacterController class when we add the Character Controller component to our game object. The Move() function will return the CollisionFlags, which will tell us which part of our character hits other collider objects.

Then, we will apply the built-in third-person character controller script to our character, and take a look at the script to get the basic idea for creating the custom character control script and camera.

After that we will get rid of the built-in script and start creating the custom script to control our character's walk, run, and jump by using the Move() function in the Character Controller class. In this step, we will also create the transition between each animation clip by using the Animation class in Unity, which allows us to adjust the speed of animation clip, type of playing, and fading time. Next, we will create the camera script to follow our character. We will then attach the script to our character and make it move on the level.

Why Is It Awesome?

After we complete this chapter, we will know how to set up the animation clip from FBX file, which we already exported from another 3D software. We will also be able to create a custom controller script to control our character in the 3D world and blend the animation from idle to walk, walk to run and jump, and so on. We will also learn how to create the third-person camera to follow our character.

This chapter will give you an understanding of how to create the third-person character control script and you will be able to use it for other controllers.

Your Hotshot Objectives

Even though Unity is already provided with built-in third-person controller script, we will create our third-person controller to get a good understanding of how to use the built-in character controller. Here is what we will learn:

  • Setting up character animation and level
  • Creating character controller and built-in script
  • Creating a custom character control script
  • Creating cross fade animation
  • Creating a third-person camera to follow our character

Mission Checklist

As we have already learned how to export the FBX file format from 3D Studio Max in the previous chapter, we will download the new chapter package, which will include the new FBX character with all the animation cycles, textures, and necessary assets for this chapter. Download the Chapter4 package from this book's website, unzip it, and then you will see Chapter4.unitypackage, which will contain all the assets for this chapter.

Note

There is also a built-in animation system in Unity (that we will not cover in this chapter), which we can use to animate a simple object such as a moving platform or the animation of an opening door. You can get more details from the following Unity website:

http://unity3d.com/support/documentation/Manual/Animation.html.

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

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