- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
 
- 纳金币
- -1
- 精华
- 11
|
In part 2 of our 3rd person character controller tutorial for Unity we set the input settings and the animation sequences for the player character, now we shall place the character into the scene and add the Character Controller object. We will also position the camera so that we can see the character from behind.
Place the Character
To place the character into the scene, drag it from the Project Panel into the scene view. When you do this the character will be in the scene and an entry will appear in the Hierarchy.
You will probably need to position the character, so grab the translate tool and with the character selected position it in the middle of the scene and make sure that its feet are touching the ground (but not going through the ground else the character will fall through).
You can use the gizmo in the top right of the viewport to switch between top down, side, front and perspective modes to make life easier. When the character is positioned it should look something like the screenshot below.
![]()
Apply a Character Controller Component
Now that the character is in the scene we need to apply a "Character Controller" component to it so that Unity knows that this object is a playable character, so with the character selected in the Hierarchy go to:
Component -> Physics -> Character Controller
When the prefab warning appears click "Add" to accept the change and continue. With the controller component added we need to scale the collision capsule so that it is the same size as the character and so that its positioned around the character.
In the inspector you will see the character controller settings when the character is selected, switching to front and side views you need to adjust the height and radius to match the character and the Center values so that the capsule is in the correct position.
![]()
So for our test character set the height to 1.85, radius to 0.4 and the Y center value to 0.93; if your using your own character the settings may be different.
The aim is to get the capsule to fit around the character as snugly as possible and to ensure the capsule does not poke through the terrain/ground; like pictured below:
![]()
Position the Camera
Now we will position the camera, so select the Main Camera in the Hierarchy and move it so that it is behind the character and rotate it slightly so its looking at the character from a slight angle.
![]()
If you play the game now you will see the character, with the idle cycle animating through. You however cannot move the character around, this is because we need to write a script to accept input from the player which will then manipulate that controller component and tell the character model to switch to different animation cycles. So in part 4 we will create the controller script.
由 u8 发表 |
|