Exemple #1
0
 private IEnumerator SynDir()
 {
     while (true)
     {
         if (!IsDead)
         {
             maxRotateChange = GameConst.Instance.TowerMaxRotateChange;
             var curDir  = transform.eulerAngles.y;
             var diffDir = tarDir - curDir;
             var diffY   = Util.NormalizeDiffDeg(diffDir);
             var dy      = Mathf.Clamp(diffY, -maxRotateChange, maxRotateChange);
             var tarDir2 = Quaternion.Euler(new Vector3(0, curDir + dy, 0));
             transform.rotation = tarDir2;
         }
         yield return(new WaitForFixedUpdate());
     }
 }
Exemple #2
0
        private void Update()
        {
            if (IsDie)
            {
                return;
            }

            if (target == null)
            {
                RunForward();
                return;
            }

            var dir = target.transform.position - transform.position;

            dir.y = 0;
            //HitTarget
            if (dir.sqrMagnitude < 1)
            {
                HitSomething();
            }
            else
            {
                dir.Normalize();

                var curDir  = transform.forward;
                var diffDir = Quaternion.FromToRotation(curDir, dir);
                var diffY   = diffDir.eulerAngles.y;
                diffY = Util.NormalizeDiffDeg(diffY);
                var oldY = this.transform.rotation.eulerAngles.y;

                var dy     = Mathf.Clamp(diffY, -15, 15);
                var newDir = Quaternion.Euler(new Vector3(0, oldY + dy, 0));
                transform.rotation = newDir;
                var forward = transform.forward;
                transform.position += forward * velocity * Time.deltaTime;
            }
        }