コード例 #1
0
        protected IEnumerator MoveToTargetCell(Vector3 basePosition, Quaternion baseRotation)
        {
            _controlEnable = false;
            float t = 0;

            Vector3    targetPos;
            Quaternion targetRot;

            MathCustom.SphericalToCartesian(movingDistance, ActualPolar, Elevation, out targetPos);
            targetPos = baseTransform.TransformPoint(targetPos);
            Vector3 cross = Vector3.Cross(baseTransform.position - targetPos, baseTransform.up);

            targetRot = Quaternion.LookRotation(baseTransform.position - targetPos, Vector3.Cross(cross, baseTransform.position - targetPos));

            while (t < 1)
            {
                if (t > 1)
                {
                    t = 1;
                }
                else
                {
                    t += Time.deltaTime * 1.25f;
                }
                transform.position = Vector3.Slerp(basePosition, targetPos, t);
                transform.rotation = Quaternion.Slerp(baseRotation, targetRot, t);
                yield return(null);
            }
            _controlEnable = true;
            StopAllCoroutines();
        }
コード例 #2
0
        public void TransformCameraTarget(Transform targetTransform, out Vector3 outPosition, out Quaternion outRotation, ECameraTargetType view)
        {
            if (view == ECameraTargetType.MAP)
            {
                Vector3 lpos = targetTransform.position;
                outPosition = lpos + (lpos.normalized * MapViewDistance);

                Vector3 upVector      = lpos.normalized;
                Vector3 rightVector   = Vector3.Cross(upVector, Vector3.up).normalized;
                Vector3 forwardVector = MathCustom.GetFaceNormalVector(Vector3.zero, rightVector, upVector);
                outRotation = Quaternion.LookRotation(-upVector, forwardVector);
            }
            else if (view == ECameraTargetType.ZOOM)
            {
                Vector3 lpos = targetTransform.position;

                Vector3 newPosition;
                MathCustom.SphericalToCartesian(DistanceToplayer, -Mathf.PI / 2, Elevation, out newPosition);
                outPosition = targetTransform.TransformPoint(newPosition + Vector3.up * StepHeight);

                Vector3 newPos = targetTransform.TransformPoint(newPosition);
                Vector3 cross  = Vector3.Cross(newPos, targetTransform.forward);
                outRotation = Quaternion.LookRotation(lpos - newPos, Vector3.Cross(cross, -(lpos - newPos)));
            }
            else
            {
                outPosition = Vector3.zero;
                outRotation = Quaternion.identity;
            }
        }
コード例 #3
0
 protected void Update()
 {
     if (_controlEnable)
     {
         Vector3 newPosition;
         MathCustom.SphericalToCartesian(movingDistance, ActualPolar, Elevation, out newPosition);
         transform.position = baseTransform.TransformPoint(newPosition);
         Vector3 cross = Vector3.Cross(baseTransform.position - transform.position, baseTransform.up);
         transform.rotation = Quaternion.LookRotation(baseTransform.position - transform.position, Vector3.Cross(cross, baseTransform.position - transform.position));
     }
 }