Configuring a player controller

So, far we have taken a lot of time to shape our world and populate it with cherry trees and spawn points, and prepare it for cucumber patches. We have been creating the game world for our player character, the Cucumber Man, to exist in. It is now time to add our Cucumber Man to our game.

Here are the steps to add the Cucumber Man to our game and to configure the controller:

  1. In the Project panel, select Prefabs
  2. Drag the CucumberMan prefab to the Hierarchy panel. Use the following screenshot as a reference to ensure that you are dragging the highlighted prefab illustrated in the following screenshot. Note that the subordinate Cucumbor_Man has been intentionally misspelled to help ensure the CucumberMan prefab is used:
  1. In the Hierarchy panel, select Main Camera.
  2. With the Main Camera selected, click the Add Component button in the Inspector panel.
  3. Select Scripts | Camera Follower to add the Camera Follower script to the Main Camera.
  4. In the Camera Follower component of the Main Camera, in the Inspector panel, change the Movement Smoothness to 5.
  5. In the Camera Follower component of the Main Camera, change the Rotation Smoothness to 5.
  6. In the Hierarchy panel, click the gray triangle to the left of CucumberMan. This will expose the subordinate components.
  7. Reselect the Main Camera in the Hierarchy panel. 
  8. Click the GameObject under CucumberMan in the Hierarchy panel and drag it to the Follow Target field in the Camera Follower component of the Main Camera.
  9. Ensure that the Can Follow checkbox is checked.

Your Camera Follower component of the main camera should look identical to the following image. If it is not identical, please revisit steps 6 through 11:

Next, we will edit the Player Motor (Script) component of the CucumberMan. Follow these important steps to properly configure the Player Motor (Script) component:

  1. In the Hierarchy panel, select the CucumberMan
  2. Expand, if necessary, the Player Motor (Script) component of the CucumberMan in the Inspector panel
  3. Drag the Main Camera from the Hierarchy panel to the Cam field in the Player Motor (Script) component of CucumberMan in the Inspector panel

Next, let's position the Cucumber Man to a logical start location for our game. Where you place the Cucumber Man is up to you. It is recommended that it be placed on one of the respawn points. Once you know where you want the character to start each game, follow these steps:

  1. In the Hierarchy panel, select CucumberMan.
  2. Using the transform tools, move the character to one of the spawn points.
  3. Zoom in and ensure the character's feet are on or slightly above the ground. We still have one more step to make the Cucumber Man our game's playable character.
  4. With the CucumberMan still selected, select the Tag drop-down menu in the Inspector panel and select Player. This will make it easier for us to reference collisions. You will learn more about this in Chapter 10, Scripting Our Points System.

You can now put the game into game-mode and test the player character. You can use the keyboard keys listed in the following table to control the Cucumber Man:

Keyboard Key Action
W Walk Up
A Walk Left
S Walk Down
D Walk Right
E Throw
Left-Hand Shift Key Run
Spacebar Jump

 

In the next section, we will fine-tune the Cucumber Man.

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

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