예제 #1
0
    void LookAtTarget()
    {
        // Determine which direction to rotate towards
        Vector3 targetDirection = target.position - transform.position;

        // The step size is equal to speed times frame time.
        float singleStep = turnSpeed * Time.fixedDeltaTime / 10;

        // Rotate the forward vector towards the target direction by one step
        Vector3 newDirection = Vector3.RotateTowards(transform.forward, targetDirection, singleStep, 0.0f);

        // Calculate a rotation a step closer to the target and applies rotation to this object
        transform.rotation = Quaternion.LookRotation(newDirection);
    }
예제 #2
0
    void FixedUpdate()
    {
        if (skipUpdate)
        {
            return;
        }

        float horizontal = Input.GetAxis("Horizontal");

        bool hasHorizontalInput = !Mathf.Approximately(horizontal, 0f);

        if (!hasHorizontalInput)
        {
            m_RowPerformed = false;
        }

        if (!m_RowPerformed && hasHorizontalInput)
        {
            m_Movement = transform.forward * moveSpeed;

            m_RotationTowards     = (horizontal < 0) ? Quaternion.Euler(0, 45, 0) : Quaternion.Euler(0, -45, 0);
            m_RotationSuppression = 1.0f;

            m_RowPerformed = true;
            if (horizontal > 0)
            {
                m_Animator.SetTrigger("swingRight");
            }
            else
            {
                m_Animator.SetTrigger("swingLeft");
            }
            AudioManager.Instance.Play("oar swing");
        }

        m_Rigidbody.MovePosition(m_Rigidbody.position + m_Movement);
        m_Movement *= moveSuppressionFactor;

        Vector3 desiredForward = Vector3.RotateTowards(
            transform.forward, m_RotationTowards * transform.forward,
            rotationSpeed * m_RotationSuppression * Time.fixedDeltaTime, 0f);

        m_Rotation = Quaternion.LookRotation(desiredForward);
        m_Rigidbody.MoveRotation(m_Rotation);
        m_RotationSuppression *= rotationSuppressionFactor;

        m_LastPosition    = m_CurrentPosition;
        m_CurrentPosition = transform.position;
    }
예제 #3
0
        public static Vector3d RotateTowards(Vector3d current, Vector3d target, double maxRadiansDelta, double maxMagnitudeDelta)
        {
            Vector3 v3 = Vector3.RotateTowards((Vector3)current, (Vector3)target, (float)maxRadiansDelta, (float)maxMagnitudeDelta);

            return(new Vector3d(v3));
        }
예제 #4
0
        public static DVector3 RotateTowards(DVector3 current, DVector3 target, double maxRadiansDelta, double maxMagnitudeDelta)
        {
            Vector3 v3 = Vector3.RotateTowards((Vector3)current, (Vector3)target, (float)maxRadiansDelta, (float)maxMagnitudeDelta);

            return(new DVector3(v3));
        }