Ejemplo n.º 1
0
 public void ActiveTrace(bool state)
 {
     if (TraceL != null && TraceR != null)
     {
         if (state == false)
         {
             TraceL.RemoveAll();
             TraceR.RemoveAll();
         }
         TraceL.enabled = state;
         TraceR.enabled = state;
     }
 }
Ejemplo n.º 2
0
    private void UpdateSliding()
    {
        bool lastInput = m_slidingInput;

        m_slidingInput = gamePadState.State.Buttons.RightShoulder == ButtonState.Pressed || gamePadState.State.Buttons.LeftShoulder == ButtonState.Pressed;

        m_slidingCoef = m_angularBySpeed.Evaluate(m_speed);
        if (m_sliding)
        {
            m_slidingCoef *= m_slidingAngularCoef;
        }

        float slideInput        = m_sliddingRight ? gamePadState.State.ThumbSticks.Left.X : -gamePadState.State.ThumbSticks.Left.X;
        float clampedSlideInput = Mathf.Clamp01(slideInput);

        m_maxSliding = Mathf.Max(clampedSlideInput, m_maxSliding);

        m_slidingCoef *= m_maxSliding;

        if (m_slidingInput && m_touchGround && !lastInput)
        {
            m_jump = m_jumpAmplitude;
        }
        else
        {
            m_jump = 0;
        }

        if (m_slidingInput && m_touchGround && m_speed > 5)
        {
            if (!m_sliding)
            {
                m_sliding = true;
                if (gamePadState.State.ThumbSticks.Left.X > 0)
                {
                    m_sliddingRight = true;
                }
                else
                {
                    m_sliddingRight = false;
                }

                m_trace.enabled     = true;
                m_slidingStateTimer = 0;
            }
            if (m_curDotFriction > 0)
            {
                m_curDotFriction -= m_dt * m_frictionDownSpeed;
                if (m_curDotFriction < 0)
                {
                    m_curDotFriction = 0;
                }
            }
            m_slidingDir    = m_sliddingRight ? m_transform.right : m_transform.rotation * -Vector3.right;
            m_acceleration += m_slidingAcc * m_slidingDir * m_slidingCoef * m_speed * Mathf.Abs(m_angularVelocity) * m_dt;

            float sliding = (m_maxSliding + slideInput);

            m_currentMaxAngularVelocity = sliding * m_maxAngularVelocity;
            m_angularAcceleration       = sliding * (m_sliddingRight ? m_currentMaxAngularAcc : -m_currentMaxAngularAcc);
            m_slidingStateTimer        += m_dt;
        }
        else
        {
            if (m_sliding)
            {
                m_sliding = false;
                m_trace.RemoveAll();
                m_trace.enabled     = false;
                m_maxSliding        = 0;
                m_slidingStateTimer = 0;
            }

            if (m_curDotFriction < m_dotFriction)
            {
                m_curDotFriction = m_slidingUp.Evaluate(m_slidingStateTimer);
            }

            m_angularAcceleration = gamePadState.State.ThumbSticks.Left.X * m_currentMaxAngularAcc;
            m_slidingStateTimer  += m_dt;
        }

        if (m_sliding)
        {
            //m_currentMaxAngularVelocity = m_maxAngularVelocity * m_slidingCoef;
            //m_currentMaxAngularAcc = m_maxAngularAcceleration * m_slidingCoef;
        }
        else
        {
            m_currentMaxAngularVelocity = m_maxAngularVelocity;
            m_currentMaxAngularAcc      = m_maxAngularAcceleration;
        }
    }