博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
[原]unity3D 相机跟随
阅读量:6897 次
发布时间:2019-06-27

本文共 984 字,大约阅读时间需要 3 分钟。

using UnityEngine;

using System.Collections;
public class CameraFollow : MonoBehaviour {
    
        public Transform target;
        private Vector3 wantedPosition;
    
        private float currentX;
        private float currentY;
        private float currentZ;
    
        private float xVelocity = 0.0F;
        private float yVelocity = 0.0F;
        private float zVelocity = 0.0f;
        private float distanceSnapTime = 0.1f;
    
    // Update is called once per frame
    void Update () {
    
            Vector3 targetPos = target.position;
            
            wantedPosition.x =  targetPos.x;
            
            wantedPosition.z = targetPos.z - 5f;//Vector3.forward*distance;   
            
            wantedPosition.y = targetPos.y -2f;// + heightAbovePlayer;
            
            currentX = Mathf.SmoothDamp(currentX, wantedPosition.x, ref xVelocity, distanceSnapTime);
            
            currentY = Mathf.SmoothDamp(currentY, wantedPosition.y, ref yVelocity, distanceSnapTime);
            
            currentZ = Mathf.SmoothDamp(currentZ, wantedPosition.z, ref zVelocity, 0.5f);
            
            transform.position = new Vector3(currentX,currentY,currentZ);
            transform.LookAt(transform.position + new Vector3(0f,0.95f,1));
    }
}

转载地址:http://zzddl.baihongyu.com/

你可能感兴趣的文章
华章11-12月份新书简介(2017年)
查看>>
第三周作业
查看>>
Vector、ArrayList、List使用深入剖析
查看>>
【调试】Core Dump是什么?Linux下如何正确永久开启?
查看>>
新浪微博API授权
查看>>
电子政务网中信息共享机制的重要性
查看>>
【Visual C++】游戏开发笔记十四 游戏画面绘图(四) 华丽的CImage类
查看>>
Struts2的配置
查看>>
[BZOJ1296][SCOI2009]粉刷匠(DP)
查看>>
Executor执行框架
查看>>
[FMX] Android APP 启动黑屏优化补丁
查看>>
常用JavaScript的高级技巧
查看>>
bzoj 1670: [Usaco2006 Oct]Building the Moat护城河的挖掘
查看>>
mac编辑器vim美化
查看>>
MD5摘要算法简析
查看>>
《30天自制操作系统》学习笔记一
查看>>
Python.tornado.2.tornado.options
查看>>
mysql关于or的索引问题
查看>>
装在u盘的linux
查看>>
ASP.NET几种页面数据绑定的用法及区别: <%#、 <%=、 <% 、<%@
查看>>