コード例 #1
0
        void FixedUpdate()
        {
            if (Mathf.Approximately(Time.timeScale, 0f))
            {
                return;
            }

            if (m_RepositionPositionDelta.sqrMagnitude > float.Epsilon || m_RepositionRotationDelta != Quaternion.identity)
            {
                m_Rigidbody.MovePosition(m_Rigidbody.position + m_RepositionPositionDelta);
                m_Rigidbody.MoveRotation(m_RepositionRotationDelta * m_Rigidbody.rotation);
                m_RepositionPositionDelta = Vector3.zero;
                m_RepositionRotationDelta = Quaternion.identity;
                return;
            }

            m_RigidbodyPosition = m_Rigidbody.position;

            KartStats.GetModifiedStats(m_CurrentModifiers, defaultStats, ref m_ModifiedStats);
            ClearTempModifiers();

            Quaternion rotationStream = m_Rigidbody.rotation;

            float deltaTime = Time.deltaTime;

            m_CurrentGroundInfo = CheckForGround(deltaTime, rotationStream, Vector3.zero);

            if (m_CurrentGroundInfo.isGrounded && !m_IsGrounded)
            {
                OnBecomeGrounded.Invoke();
            }

            if (!m_CurrentGroundInfo.isGrounded && m_IsGrounded)
            {
                OnBecomeAirborne.Invoke();
            }

            m_IsGrounded = m_CurrentGroundInfo.isGrounded;

            GroundInfo nextGroundInfo = CheckForGround(deltaTime, rotationStream, m_Velocity * deltaTime);

            GroundNormal(deltaTime, ref rotationStream, m_CurrentGroundInfo, nextGroundInfo);
            TurnKart(deltaTime, ref rotationStream);

            StartDrift(m_CurrentGroundInfo, nextGroundInfo, rotationStream);
            StopDrift(deltaTime);

            CalculateDrivingVelocity(deltaTime, m_CurrentGroundInfo, rotationStream);

            Vector3 penetrationOffset = SolvePenetration(rotationStream);

            penetrationOffset = ProcessVelocityCollisions(deltaTime, rotationStream, penetrationOffset);

            rotationStream = Quaternion.RotateTowards(m_Rigidbody.rotation, rotationStream, rotationCorrectionSpeed * deltaTime);

            AdjustVelocityByPenetrationOffset(deltaTime, ref penetrationOffset);

            m_Rigidbody.MoveRotation(rotationStream);
            m_Rigidbody.MovePosition(m_RigidbodyPosition + m_Movement);
        }
コード例 #2
0
        void FixedUpdate()
        {
            if (Mathf.Approximately(Time.timeScale, 0f))
            {
                return;
            }

            if (m_RepositionPositionDelta.sqrMagnitude > float.Epsilon || m_RepositionRotationDelta != Quaternion.identity)
            {
                m_Rigidbody.MovePosition(m_Rigidbody.position + m_RepositionPositionDelta);
                m_Rigidbody.MoveRotation(m_RepositionRotationDelta * m_Rigidbody.rotation);
                m_RepositionPositionDelta = Vector3.zero;
                m_RepositionRotationDelta = Quaternion.identity;
                return;
            }

            m_RigidbodyPosition = m_Rigidbody.position;

            KartStats.GetModifiedStats(m_CurrentModifiers, defaultStats, ref m_ModifiedStats);
            ClearTempModifiers();

            Quaternion rotationStream = m_Rigidbody.rotation;

            float deltaTime = Time.deltaTime;

            //Para MRU
            if (m_Racer.GetLapTime() > 1 && m_ModifiedStats.acceleration == 5)
            {
                m_ModifiedStats.acceleration = 0f;
                //Debug.Log(deltaTime);
            }
            ;
            // Para MRUV
            if (m_Racer.GetLapTime() > 0f && m_Racer.GetLapTime() < 0.5f && m_ModifiedStats.acceleration == 1)
            {
                if (ace)
                {
                    acelerar_mruv += 1.5f;
                    ace            = false;
                }
                m_ModifiedStats.acceleration = acelerar_mruv;
                //Debug.Log(deltaTime);
            }
            ;
            if (m_Racer.GetLapTime() > 0.5f)
            {
                ace = true;
            }

            m_CurrentGroundInfo = CheckForGround(deltaTime, rotationStream, Vector3.zero);

            Hop(rotationStream, m_CurrentGroundInfo);

            if (m_CurrentGroundInfo.isGrounded && !m_IsGrounded)
            {
                OnBecomeGrounded.Invoke();
            }

            if (!m_CurrentGroundInfo.isGrounded && m_IsGrounded)
            {
                OnBecomeAirborne.Invoke();
            }

            m_IsGrounded = m_CurrentGroundInfo.isGrounded;

            ApplyAirborneModifier(m_CurrentGroundInfo);

            GroundInfo nextGroundInfo = CheckForGround(deltaTime, rotationStream, m_Velocity * deltaTime);

            GroundNormal(deltaTime, ref rotationStream, m_CurrentGroundInfo, nextGroundInfo);
            TurnKart(deltaTime, ref rotationStream);

            StartDrift(m_CurrentGroundInfo, nextGroundInfo, rotationStream);
            StopDrift(deltaTime);

            CalculateDrivingVelocity(deltaTime, m_CurrentGroundInfo, rotationStream);

            Vector3 penetrationOffset = SolvePenetration(rotationStream);

            penetrationOffset = ProcessVelocityCollisions(deltaTime, rotationStream, penetrationOffset);

            rotationStream = Quaternion.RotateTowards(m_Rigidbody.rotation, rotationStream, rotationCorrectionSpeed * deltaTime);

            AdjustVelocityByPenetrationOffset(deltaTime, ref penetrationOffset);

            m_Rigidbody.MoveRotation(rotationStream);
            m_Rigidbody.MovePosition(m_RigidbodyPosition + m_Movement);

            //rb.GetPointVelocity(transform.TransformPoint(localWheelPos));
            //Debug.Log(LocalSpeed);
        }