怎么在unity5里添加unity官方第三人称称?

登录后你可以:
首次使用?
专业挖坑,业余搬运
视频地址复制
Flash地址复制
Html地址复制
离线看更方便
用或其他应用扫描二维码
/watch?v=dXzF-S9tVrM Unity民间教程,搬运自youtube。本视频一切权益属于原作者:SpeedTutor。
如有有志向于传播Unity教程,愿意挺身而出制作字幕/后期的同学(边学边传)请私信我。[]~( ̄▽ ̄)~*
PS:只要四分钟!
广播电视节目制作经营许可证:(沪)字第1248号
| 网络文化经营许可证:沪网文[6号 | 信息网络传播视听节目许可证:0910417 | 互联网ICP备案:沪ICP备号-3 沪ICP证:沪B2- | 违法不良信息举报邮箱: | 违法不良信息举报电话:转3unity 第三人称 - CSDN博客
unity 第三人称
转自:/tutorials/unity3d-third-person-cameras--mobile-11230
The camera is one of the most important elements in a 3D game. It acts as the player's eyes, letting them see the game world from different points of view. In Unity3D, a 3D camera works just like a film camera. It can be panned, tilted, and zoomed to frame
scenes. This tutorial will teach you how to create multiple third person camera perspectives.
Project Setup
We need a simple project to test our camera scripts in. We'll need a scene with a ground plane that has a texture on it. This will make it easy to see how each camera moves and reacts to player inputs. When we're done, it should look like this:
Follow these steps to setup the project:
Click File & New ProjectName your project folder&3rd Person CamerasClick CreateClick GameObject & Create Other & Directional LightClick GameObject & Create Other & PlaneIn the Inspector, find the Transform component and change the position X to 0, Y to -0.5 and Z to 0 so it will sit below the cubeDownload&Drag&&into the Project panelDrag the grid texture from the project panel onto the Plane in the Hierarchy panelSelect the Main Camera and move and rotate it into a position above and behind the cubeSave your Scene (File & Save Scene) and name it&Main
Create a Player
All of the cameras we're going to create will need a target: something to look at or follow. So, let's create a basic player we can move around with the arrow keys.
Click GameObject & Create Other & CubeRename it PlayerIn the inspector, make sure its X, Y, and Z coordinates are all set to zero so we're sure the player is at the center of the 3D worldClick Assets & Create & C# ScriptName the script PlayerDrag the Player script from the Project panel onto the Player in the Hierarchy panel
In the Player script, add two public properties for the movement and turning speed. Then add the following code to your Update() method:
public class Player : MonoBehaviour {
public float movementSpeed = 10;
public float turningSpeed = 60;
void Update() {
float horizontal = Input.GetAxis(&Horizontal&) * turningSpeed * Time.deltaT
transform.Rotate(0, horizontal, 0);
float vertical = Input.GetAxis(&Vertical&) * movementSpeed * Time.deltaT
transform.Translate(0, 0, vertical);
This gives the player controls similar to those of a tank. The horizontal axis (the left-or-right keys) turn the player around, while the vertical axis (up-or-down keys) move the player forward and backward.
The Look At Camera
This is the most basic 3rd person camera. It sits in a fixed location in the 3D world and tracks its target like a turret.
Click Assets & Create & C# ScriptName the script LookAtCameraDrag the LookAtCamera script from the Project panel onto the Main Camera in the Hierarchy panel
In the LookAtCamera script, create a public attribute for our camera's target at the top of the class. Public attributes are exposed in the Inspector and will allow us to assign the Player as the camera's target:
public class LookAtCamera : MonoBehaviour {
public GameO
Next, we need to tell our camera's transform to look at the target object. Thankfully, transform objects have a convenient LookAt() method we can use to do just that. We could do this in the Update() method, but
instead we create a LateUpdate() method. As a rule of thumb, you should always use LateUpdate() instead of the Update() method in all camera scripts. LateUpdate() happens after Update() has finished, so the Player script has a chance to finish calculating
the player's position before the camera calculates its position. This results in smoother camera motion:
void LateUpdate() {
transform.LookAt(target.transform);
The final script should look like:
public class LookAtCamera : MonoBehaviour {
public GameO
void LateUpdate() {
transform.LookAt(target.transform);
If you try to run the game now, you'll get errors complaining about UnassignedReferenceException. To prevent this, drag the Player from the Hierarchy panel and drop it on the script's Target property in the Inspector.
The camera now has a valid target to look at.
The Dungeon Crawler Camera
This is the type of camera you'd typically find in games like Diablo, also known as a &dungeon crawler& game. The camera sits above the player and moves relative to the character, but never rotating.
Click Assets & Create & C# ScriptName the script DungeonCameraDrag the DungeonCamera script from the Project panel onto the Main Camera in the Hierarchy panel
In the DungeonCamera script, we once again need to create a public attribute for our camera's target. We also need to create a variable to store the offset between the camera and its target. The offset is represented as a Vector3 and will be used maintain the
relative distance as the player moves around. You may notice that we don't give the offset a value when we first declare it. This is because we'll be calculating the value the first time the script is run. We can use the Start() method to do this:
public class DungeonCamera : MonoBehaviour {
public GameO
void Start() {
offset = transform.position - target.transform.
In each frame we need to update the camera's position based on the player's position by applying the offset. As usual, this should be done in the LateUpdate() method:
void LateUpdate() {
Vector3 desiredPosition = target.transform.position +
tranform.position = desiredP
Drag the Player from the Hierarchy panel to the script's Target property in the Inspector.
Optional Enhancements
You may notice that the camera movement is a bit stiff. It would be nice to dampen the movement slightly so that it takes some time to catch up to the player. We can do this using the&&method.
Lerp linearly interpolates between two points, meaning it smoothly transitions from one point to another in a straight line.
In order to control how much damping is applied, we can create another public attribute called, what else, damping!
public float damping = 1;
The two points we can lerp between are the current position of the camera with damping applied, and the desired position with no damping.
void LateUpdate() {
Vector3 desiredPosition = target.transform.position +
Vector3 position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * damping);
transform.position =
Finally, we want the camera to keep looking at the player:
transform.LookAt(target.transform.position);
The final script looks like this:
public class DungeonCamera : MonoBehaviour {
public GameO
public float damping = 1;
void Start() {
offset = transform.position - target.transform.
void LateUpdate() {
Vector3 desiredPosition = target.transform.position +
Vector3 position = Vector3.Lerp(transform.position, desiredPosition, Time.deltaTime * damping);
transform.position =
transform.LookAt(target.transform.position);
The Follow Camera
This type of camera is commonly used in platforming games like Mario Galaxy. The camera sits behind and above the player and rotates around the character as they turn.
Click Assets & Create & C# ScriptName the script FollowCameraDrag the FollowCamera script from the Project panel onto the Main Camera in the Hierarchy panel
Like the Dungeon Crawler camera, the Follow camera is going to need a public attribute for a target, as well as an offset. The offset should be set in the Start() method:
public class FollowCamera : MonoBehaviour {
public GameO
void Start() {
offset = target.transform.position - transform.
To orient the camera behind the target, we first need to get the angle of the target and turn it into a rotation in the LateUpdate() method:
void LateUpdate() {
float desiredAngle = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0, desiredAngle, 0);
We can then multiply the offset by the rotation to orient the offset the same as the target. We then subtract the result from the position of the target.
transform.position = target.transform.position - (rotation * offset);
To keep looking at the player:
transform.LookAt(target.transform);
Drag the Player from the Hierarchy panel to the script's Target property in the Inspector.
Optional Enhancements
The same damping motion we applied to the Dungeon camera can be applied to the Follow camera. First, we add a damping attribute to make it easier to adjust the damping:
public float damping = 1;
Instead of lerping between two points like we did with the Dungeon camera, we'll be lerping between the angle of the camera and the angle of the target. So, rather than,
we use the&&method. We replace the original
angle code with:
float currentAngle = transform.eulerAngles.y;
float desiredAngle = target.transform.eulerAngles.y;
float angle = Mathf.LerpAngle(currentAngle, desiredAngle, Time.deltaTime * damping);
Quaternion rotation = Quaternion.Euler(0, angle, 0);
The final script should look like:
public class FollowCamera : MonoBehaviour {
public GameO
public float damping = 1;
void Start() {
offset = target.transform.position - transform.
void LateUpdate() {
float currentAngle = transform.eulerAngles.y;
float desiredAngle = target.transform.eulerAngles.y;
float angle = Mathf.LerpAngle(currentAngle, desiredAngle, Time.deltaTime * damping);
Quaternion rotation = Quaternion.Euler(0, angle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
The Mouse Aim Camera
This type of camera is similar to the Follow camera, except the rotation is controlled by the mouse, which then points the character in whatever direction the camera is facing.
Click Assets & Create & C# ScriptName the script DungeonCameraDrag the DungeonCamera script from the Project panel onto the Main Camera in the Hierarchy panel
Like the Follow camera, the Mouse Aim camera is going to need a public attribute for a target and rotation speed, as well as well as an offset. The offset should be set in the Start() method:
public class MouseAimCamera : MonoBehaviour {
public GameO
public float rotateSpeed = 5;
void Start() {
offset = target.transform.position - transform.
We can access the horizontal axis of the mouse (aka: Mouse X) and use it to rotate the target.
float horizontal = Input.GetAxis(&Mouse X&) * rotateS
target.transform.Rotate(0, horizontal, 0);
We then orient the offset in the same direction and subtract it from the target's position to keep the camera behind the target.
float desiredAngle = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0, desiredAngle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
Drag the Player from the Hierarchy panel to the script's Target property in the Inspector.
Unlike the other scripts, we're not going to add any damping to the camera's movement. Because of the precise nature of the mouse, it can often lead to motion sickness.
The final script should look like this:
public class MouseAimCamera : MonoBehaviour {
public GameO
public float rotateSpeed = 5;
void Start() {
offset = target.transform.position - transform.
void LateUpdate() {
float horizontal = Input.GetAxis(&Mouse X&) * rotateS
target.transform.Rotate(0, horizontal, 0);
float desiredAngle = target.transform.eulerAngles.y;
Quaternion rotation = Quaternion.Euler(0, desiredAngle, 0);
transform.position = target.transform.position - (rotation * offset);
transform.LookAt(target.transform);
}Final Thoughts
More than one camera script can be applied to a single camera at the same time. To switch between the different scripts, enable the script you want by checking it and unchecking all the others. This could be useful for switching to a different camera style
for establishing shots or cut scenes.
Unity also comes with several camera scripts you can use right out of the box. The scripts are well documented, easy to customize and make great guides for building and improving your own camera scripts.
Click Assets & Import Package & ScriptsUncheck everything except Camera Scripts
Conclusion
Unity makes it easy to build a wide variety of cameras for any type of game. With just a few lines of code, the most important element in your game is ready to go. While some may find the math a little intimidating, Unity provides so many useful convenience
functions that most of the heavy calculations are already done for you.
&to download the complete Unity
本文已收录于以下专栏:
相关文章推荐
http://blog.csdn.net/mobanchengshuang/article/details/
转载地址:http://blog.csdn.net/libeifs/article/details/6696424
Unity3D3.4
转载自:/article/111.aspx
玩过《魔兽世界》的朋友都知道,《魔兽世界》中的角色控制器非常的出色,Unity3D 的标准包中自带了第三人称...
第三人称控制脚本有以下两个
角色脚本:Character1.cs
using UnityE
using System.C
public class Characte...
他的最新文章
讲师:宋宝华
讲师:何宇健
您举报文章:
举报原因:
原文地址:
原因补充:
(最多只允许输入30个字)需要第三人称模拟器
(U3D自带的)
我的U3D5.31没有自带的模拟器,不知道哪里可以下载?
求各位大神帮忙,我真的很需要~
要评论请先&或者&
下载UNITY的那个网页有其他的几个DEMO的包,其中有一个就有第三人称模拟器
:下载UNITY的那个网页有其他的几个DEMO的包,其中有一个就有第三人称模拟器 在哪里?我在官网下的。登录后你可以:
首次使用?
微博@PURE_BUG /u/ opengl,持续更新ue4 u3d
视频地址复制
Flash地址复制
Html地址复制
离线看更方便
用或其他应用扫描二维码
https://youtu.be/7NktwerZFro?list=PLXoPWlNXQg8WuiBA8Nm6G0fX97SBonBlu
从油管搬运,所有原作者开始项目与已经完成项目已经被我从dropbox下载下来放到的百度云盘。
开始项目: /s/1bp3LOQV
可以跟着视频学习。
完成项目: /s/1kV357Jh
完成项目还包括Aaron Hibberd的这个unity 5教程的其他项目,下载解压后Th
广播电视节目制作经营许可证:(沪)字第1248号
| 网络文化经营许可证:沪网文[6号 | 信息网络传播视听节目许可证:0910417 | 互联网ICP备案:沪ICP备号-3 沪ICP证:沪B2- | 违法不良信息举报邮箱: | 违法不良信息举报电话:转3}

我要回帖

更多关于 unity第三人称视角 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信