zoukankan      html  css  js  c++  java
  • Unity 摄像机跟随

    方式一:将摄像机直接拖到游戏对象的下面;

    方式二:脚本实现

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class kow : MonoBehaviour
    {
        public Transform targetTr;
        public float dist = 10.0F;
        public float height = 3.0F;
        public float dampTrace = 20.0F;
    
        private Transform tr;
    
        // Start is called before the first frame update
        void Start()
        {
            tr = GetComponent<Transform>();
        }
    
        // Update is called once per frame
        void LateUpdate()
        {
            tr.position = Vector3.Lerp(tr.position, targetTr.position - (targetTr.forward * dist) + (Vector3.up * height), Time.deltaTime * dampTrace);
            tr.LookAt(targetTr.position);
        }
    }

     这里主要的是Vector3.Lerp()和函数,三个参数,第一个:起始位置;第二个:结束位置;第三个:浮点格式。

  • 相关阅读:
    超赞!不容错过的5款实用网页开发和设计工具
    如何从平面设计转行到UI设计?
    线段树
    RMQ
    Splay
    Treap
    *模板--矩阵
    最小生成树
    hash
    ac自动机
  • 原文地址:https://www.cnblogs.com/Optimism/p/10692849.html
Copyright © 2011-2022 走看看