示例#1
0
    void ReleaseControl(ExitType EExitType)
    {
        if (m_controlled)
        {
            m_bPhysicAnim = false;

            // keep release time
            if (EExitType != ExitType.ClimbExit)
            {
                m_releaseTime = Time.time;
            }

            // Leave control
            m_controlled.EventListeners.ForEach(e => e.OnEdgeGrabEnd(this));
            m_controlled.IsControlled = false;

            // exit with small impulse
            if (EExitType == ExitType.Jump)
            {
                APCharacterMotor motor = m_controlled.GetMotor();
                motor.m_velocity = m_jumpExitPower;

                float horAxis = m_controlled.m_inputs.m_axisX.GetValue();
                motor.m_velocity.x *= horAxis;

                // make sure to exit in right side
                if ((motor.m_velocity.x > 0f && !motor.FaceRight) || (motor.m_velocity.x < 0f && motor.FaceRight))
                {
                    motor.Flip();
                }
            }
            else if (EExitType == ExitType.ClimbExit)
            {
                float fClampedInput = GetClampedInput();

                // inject exit character velocity
                float fGroundSpeed = m_controlled.ComputeMaxGroundSpeed();
                m_controlled.GetMotor().m_velocity = Vector2.right * fClampedInput * fGroundSpeed;

                // limit exit input
                m_controlled.m_inputs.m_axisX.ResetValue(fClampedInput);
            }

            m_controlled = null;
        }
    }