- 最后登录
- 2014-10-23
- 注册时间
- 2011-7-19
- 阅读权限
- 90
- 积分
- 81303
- 纳金币
- -1
- 精华
- 11
|
If you've been following our 3rd person character controller for Unity tutorial so far you will have a playable character in your game world, however there are two flaws with the system we have created.
1. The camera does not follow the character.
2. The character can walk up very steep/sheer inclines on the terrain.
Of course we shall now address both of these issues.
Camera Following
When the character is walking we want the camera to follow the character from behind. There are three common ways of doing this:
1. Dragging the Main Camera in the Hierarchy onto the character prefab in the Hierarchy, which binds the camera to the controller.
2. Creating a smooth follower camera, which is bound to the character
3. Creating an orbital camera.
The first method is the easiest, just drag the camera in the hierarchy onto the character in the hierarchy to set the camera as a child of the character. This is easy and works if you want to test it out. However the movement is a bit harsh, its not the nicest follower.
With the second method, we apply a smooth follow component to the camera and attach it to the character, which results in a much nicer follower.
The third method is a bit more complex and will be the subject of another tutorial which is coming soon. So we will implement the second method in this tutorial. So follow these simple steps:
1. Select the camera in the hierarchy
2. Select Component -> Camera Control -> Smooth Follow
This has applied a smooth follow component to the camera, we now need to attach it to the character.
1. Select the Main Camera in the Hierarchy.
2. In the Inspector look for the Smooth Follow script section pictured below.
3. Set the target to the character transform.
If you test the game now the camera will follow the character but will be out of position; so we need to set the cameras position.
So set the Height and Distance settings of the smooth follow camera so that it is in the desired position. When you've got it in the right place test the game, you'll find that the camera now follows the character and smoothly moves with the character and not harshly which makes for a much more pleasant camera motion.
|
|