Beispiel #1
0
    private void UpdateCamera()
    {
        Vector2 focalPointOnMoveOffset = Vector2.Lerp(m_camera.LookAtPointOffset.OnTurn,
                                                      m_camera.LookAtPointOffset.OnMaxSpeed, SpeedFactor);

        m_lookAtPointOffset.x = Mathf.Lerp(
            m_lookAtPointOffset.x,
            Mathf.Lerp(
                m_camera.LookAtPointOffset.OnIdle.x,
                focalPointOnMoveOffset.x * Mathf.Sign(SmoothedInput.y),
                Mathf.Abs(SmoothedInput.y)),
            m_camera.LookAtPointOffset.Smooth.x * Time.deltaTime);

        m_lookAtPointOffset.y = Mathf.Lerp(
            m_lookAtPointOffset.y,
            Mathf.Lerp(
                m_camera.LookAtPointOffset.OnIdle.y,
                focalPointOnMoveOffset.y * Mathf.Sign(SmoothedInput.x),
                Mathf.Abs(SmoothedInput.x)),
            m_camera.LookAtPointOffset.Smooth.y * Time.deltaTime);

        Vector3 lookTargetPosition = CachedTransform.position + CachedTransform.right * m_lookAtPointOffset.x +
                                     CachedTransform.up * m_lookAtPointOffset.y;

        Vector3 lookTargetUpVector = (CachedTransform.up + CachedTransform.right *
                                      SmoothedInput.z * m_camera.OnRollCompensationFactor).normalized;

        Quaternion targetCameraRotation = Quaternion.LookRotation(lookTargetPosition -
                                                                  m_cachedCameraTransform.position, lookTargetUpVector);

        m_cachedCameraTransform.rotation = Quaternion.Slerp(m_cachedCameraTransform.rotation,
                                                            targetCameraRotation, m_camera.RotationSmooth * Time.deltaTime);

        Vector3 cameraOffset = CachedTransform.TransformDirection(CameraOffsetVector);

        m_cachedCameraTransform.position = Vector3.Lerp(m_cachedCameraTransform.position,
                                                        CachedTransform.position + cameraOffset, m_camera.PositionSmooth * Time.deltaTime);

        float idleCameraDistance = cameraOffset.magnitude + (cameraOffset.normalized * m_spaceship.SpeedRange.x *
                                                             Time.deltaTime / m_camera.PositionSmooth).magnitude;

        m_idleCameraDistance = Mathf.Lerp(m_idleCameraDistance, idleCameraDistance, IdleCameraDistanceSmooth * Time.deltaTime);
        float baseFrustumHeight = 2.0f * m_idleCameraDistance * Mathf.Tan(m_initialCameraFOV * 0.5f * Mathf.Deg2Rad);

        m_camera.TargetCamera.fieldOfView = 2.0f * Mathf.Atan(baseFrustumHeight * 0.5f / Vector3.Distance(
                                                                  CachedTransform.position, m_cachedCameraTransform.position)) * Mathf.Rad2Deg;
    }
Beispiel #2
0
    void UpdateMove()
    {
        const float runThreshold = 0.1f;
        const float runSpeed     = 7f;                  // 前進速度
        const float jumpSpeed    = 4.5f;                // ジャンプ中の前進速度

        float forwardSpeed = speed;

        if (speed > runThreshold)
        {
            forwardSpeed *= (IsJumpState) ? jumpSpeed : runSpeed;
        }

        Vector3 velocity = new Vector3(0f, 0f, forwardSpeed);           // 上下のキー入力からZ軸方向の移動量を取得

        velocity = CachedTransform.TransformDirection(velocity);        // キャラクターのローカル空間での方向に変換

        CachedTransform.localPosition += velocity * Time.deltaTime;
    }
Beispiel #3
0
        /// <summary>
        /// Calculate KLAudioSource position using current KLListener
        /// </summary>
        public Vector3 GetSourcePosition()
        {
            if (ReferenceEquals(KLListener.Current, null))
            {
                return(CachedTransform.position);
            }

            switch (sourceShape)
            {
            case SourceType.Sphere:
                return(KLMath.NearPointToSphere(CachedTransform.position, sphereShapeRadius, KLListener.Current.CachedTransform.position));

            case SourceType.Line:
                return(KLMath.ProjectPointOnLineSegment(
                           CachedTransform.TransformPoint(lineShapeStart),
                           CachedTransform.TransformPoint(lineShapeEnd),
                           KLListener.Current.CachedTransform.position
                           ));

            case SourceType.Area:
                // TODO: Move this to KLMath
                Vector3 half = areaShapeSize / 2f;
                Vector3 d    = KLListener.Current.CachedTransform.position - CachedTransform.position;
                Vector3 ld   = CachedTransform.InverseTransformDirection(d);
                ld = new Vector3(
                    Mathf.Clamp(ld.x, -half.x, half.x),
                    Mathf.Clamp(ld.y, -half.y, half.y),
                    Mathf.Clamp(ld.z, -half.z, half.z)
                    );

                return(CachedTransform.position + CachedTransform.TransformDirection(ld));

            default:
                return(CachedTransform.position);
            }
        }