• 物体朝向摄像机


    锁定物体的X轴旋转

    ========================================

    using UnityEngine;
    using System.Collections;

    public class LookAtMainCamera : MonoBehaviour
    {    
        public bool LookMode = false;

        void Update ()
        {
            var cameraPos = Camera.main.transform.position;
            var objPos = this.transform.position;
            var lookV = cameraPos - objPos;
            if (LookMode)
            {
                var crossValue = Vector3.Cross(Vector3.up, lookV);
                var crossThis = Vector3.Cross(this.transform.up, crossValue);
                this.transform.localRotation = Quaternion.LookRotation(-crossThis, Vector3.up);
            } else
            {
                this.transform.LookAt(cameraPos, Vector3.up);
            }
        }
    }

    直接转向插值 或直接lookAt

    ====================================================

    using UnityEngine;

    public class LookAtCamera : MonoBehaviour {

        public float lerpFactor = 10f;
        // Use this for initialization
        void Start () {
            
        }
        
        // Update is called once per frame
        void Update () {
            //transform.LookAt(Camera.main.transform.position);
            transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(Camera.main.transform.position - transform.position), lerpFactor * Time.deltaTime);
        }
    }

  • 相关阅读:
    datatables ajax异步分页
    redis实现消息发布/订阅
    使用Tomcat+Redis来实现集群部署中的Session共享问题
    工具:从一个文件夹中复制jar到另一个文件夹中
    CentOS配置上网
    热力图与百度地图扩展实例
    【转】JavaWeb编码之get方式中文乱码问题
    数字转换大写核心类
    详说 Navicat for MySQL 快捷键
    MYBATIS常用的sql事例
  • 原文地址:https://www.cnblogs.com/alps/p/7823510.html
Copyright © 2020-2023  润新知