纳金网

标题: unity3d第三人称角色控制教程-3 [打印本页]

作者: 会飞的鱼    时间: 2011-12-8 17:14
标题: unity3d第三人称角色控制教程-3


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 发表
作者: osaka    时间: 2011-12-9 09:11

作者: 晃晃    时间: 2012-3-13 23:20
你们都躲开,我来顶

作者: 彬彬    时间: 2012-3-16 19:43

   

作者: 奇    时间: 2012-4-3 23:28
水。。。

作者: tc    时间: 2012-6-1 23:20
顶!学习了!阅!

作者: 菜刀吻电线    时间: 2012-6-2 23:25
响应天帅号召,顶

作者: C.R.CAN    时间: 2012-8-6 23:51
“再次路过……”我造一个-----特别路过

作者: 晃晃    时间: 2012-9-24 23:27
顶!学习了!阅!

作者: tc    时间: 2012-10-4 23:22
提醒猪猪,千万不能让你看见

作者: 晃晃    时间: 2012-10-14 23:23
无聊时可以刷屏幕 灌水 也可以试试 帖子的标题究竟可以写多长

作者: 晃晃    时间: 2013-3-2 23:26
发了那么多,我都不知道该用哪个给你回帖了,呵呵

作者: C.R.CAN    时间: 2013-3-11 23:21
既来之,则看之!





欢迎光临 纳金网 (http://go.narkii.com/club/) Powered by Discuz! X2.5