首页 > 其他 > 详细

相机跟随人物

时间:2017-03-01 23:13:28      阅读:368      评论:0      收藏:0      [点我收藏+]

一.第三人称视角,一般可用于赛车游戏

先设置好相机与玩家之间的角度

技术分享

给相机添加代码

技术分享
 1 using UnityEngine;
 2 using System.Collections;
 3 
 4 namespace CompleteProject
 5 {
 6     public class CameraFollow : MonoBehaviour
 7     {
 8         public Transform target;            // The position that that camera will be following.
 9         public float smoothing = 5f;        // The speed with which the camera will be following.
10 
11 
12         Vector3 offset;                     // The initial offset from the target.
13 
14 
15         void Start ()
16         {
17             // Calculate the initial offset.
18             offset = transform.position - target.position;
19         }
20 
21 
22         void FixedUpdate ()
23         {
24             // Create a postion the camera is aiming for based on the offset from the target.
25             Vector3 targetCamPos = target.position + offset;
26 
27             // Smoothly interpolate between the camera‘s current position and it‘s target position.
28            //相机平滑的移动到目标位置,插值
29             transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
30         }
31     }
32 }
View Code

 

相机跟随人物

原文:http://www.cnblogs.com/ninomiya/p/6486534.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!