Building the panda hero

In this section, we will go through the step to create our hero: an unstoppable panda! We will build it, keeping in mind how the Player Controller will act on the panda. If you have followed the steps in Chapter 9, Look, It Moves, you will already have a panda in the scene (which we can now rename Panda Hero), and the game object should already have, besides the Transform, a Sprite Renderer as well as an Animator component in which the Controller is the Panda_Animator_Finished:

First of all, the character is definitely out of proportion (and possibly also rendered behind the terrain, which is not good). Unless we want to make a variant of Godzilla or King Kong that features a panda, we'd best change this:

In order to fix the problem that the character is rendered behind the terrain, we need to change the sorting layer in its Sprite Renderer. We can, for instance, set the Sorting Layer to 1, and the panda will be rendered on top:

And this is how it appears in the Scene view now:

However, the character is still out of proportion. Thus, we need to scale it down uniformly, to fit the environment. You can either use the Scale in Transform or select the Rect Tool and while holding Shift, drag one of the corners to scale the character uniformly. The dimensions of our character should be reasonable with respect to the environment:

The next step is to add a collider, in particular, a BoxCollider2D. Here, we need to adjust the Offset and the Size to have the collider (the green box in the Scene view) just around the character without much space unoccupied by the character. The settings that work for me are Offset = (0,0) and Size = (3.13,4.16). This is the result in the Scene view:

Also, it's good practice to set the Tag as Player. As a result, when you extend the game, you can check if a collision deals with the player, and/or locates the player's game object easier through code:

The next component is Rigidbody2D. This will allow the character to interact with the physical environment around it. Feel free to change the settings as you like. For instance, a value for the Mass equal to 3 should work pretty well. However, keep in mind that you absolutely need to check Freeze Rotation Z under the Constraints menu. Otherwise, we would end up with a rotating character, something we want to avoid:

We need to create one more thing for our character: a ground checker. This is an empty game object attached to the character, which helps us to easily have another point to check whether the character is on the ground or not. Right-click on the Panda Hero in the Hierarchy panel, and select Create Empty Game Object. Rename the new object as Ground Checker. Now, in the Inspector, next to the name there is a cube: click on it, and the label menu shows up:

Click on any of that long bar. As a result, you will be able to see where the object is placed within the Scene view:

Use the Moving Tool to bring it beneath the character, as shown in the following screenshot:

And with this, we have finished creating our character, and it's time to implement the movement of this panda.

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

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