// face enemy
        public void FaceEnemy()
        {
            GameObject obj = EnemyUtil.FindLockEnemy(transform);

            if (obj == null)
            {
                return;
            }

            Vector3 error = obj.transform.position - transform.position;

            error.y = 0;

            float desiredAngle = Mathf.Atan2(error.x, error.z) * 180.0f / Mathf.PI;

            transform.localRotation = Quaternion.Euler(0, desiredAngle, 0);
            //Quaternion.Slerp(transform.localRotation, Quaternion.Euler(0,desiredAngle,0),Time.deltaTime * 10);
        }
Esempio n. 2
0
        protected bool LockEnemyRotation()
        {
            GameObject obj = EnemyUtil.FindLockEnemy(playerObj.transform);

            if (obj == null)
            {
                return(false);
            }

            Vector3 error = obj.transform.position - transform.position;

            error.y = 0;

            float desiredAngle = Mathf.Atan2(error.x, error.z) * 180.0f / Mathf.PI;

            m_LookAngle             = Mathf.LerpAngle(m_LookAngle, desiredAngle, Time.deltaTime * m_TurnSpeed);
            m_TransformTargetRot    = Quaternion.Euler(0f, m_LookAngle, 0f);
            transform.localRotation = m_TransformTargetRot;

            return(true);
        }