zoukankan      html  css  js  c++  java
  • [原]unity3D 相机跟随

    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));
        }
    }

  • 相关阅读:
    事件总线Guava EventBus
    DDD—实体和值对象
    DDD—子域和限界上下文
    DDD—什么是领域驱动设计
    DDD—微服务,中台建设为什么需要领域驱动设计
    RabbitMQ 中的 7 种队列模式
    10w 行级别数据的 Excel 导入优化记录
    Java 反射是什么?
    21 条常用 Linux 命令
    一个 java 文件的执行过程
  • 原文地址:https://www.cnblogs.com/U-tansuo/p/CameraFollow.html
Copyright © 2011-2022 走看看