コード例 #1
0
        private void IdleCheck(ControlProperty control, StateProperty state, InputProperty input)
        {
            if (InputUtils.HasAnyInput(input) || state.HasState(State.Fall))
            {
                if (control.m_idle)
                {
                    control.m_idleTimer = 1 + Random.Range(0, 3);
                }
                control.m_idle = false;
            }
            else
            {
                control.m_idleTimer += Time.deltaTime;

                if (control.m_idleTimer >= 10)
                {
                    control.m_idle = true;
                    if (Random.Range(1, 400) == 1)
                    {
                        control.m_lookDirection = new Vector3(
                            Random.Range(-1, 1), Random.Range(-0.2f, 1), Random.Range(-1, 1)).normalized;
                    }
                }

                if (control.m_idleTimer >= 20)
                {
                    control.m_run = true;
                }
            }
        }
コード例 #2
0
 private void UpdateApplyForce(ControlProperty control, StateProperty state)
 {
     if (state.HasState(State.Dead) || state.HasState(State.Unconscious) || state.HasState(State.Fall))
     {
         control.m_applyForce = 0.1f;
     }
     else if (state.HasState(State.Jump))
     {
         control.m_applyForce = 0.5f;
     }
     else
     {
         control.m_applyForce = Mathf.Clamp(control.m_applyForce + Time.deltaTime / 2, 0.01f, 1f);
     }
 }
コード例 #3
0
 private void RunCheck(ControlProperty control, StateProperty state)
 {
     if (control.m_applyForce > 0.5f)
     {
         if (InputUtils.ValidMove(new Vector2(control.m_rawDirection.x, control.m_rawDirection.z)))
         {
             state.m_state = State.Run;
         }
         else
         {
             state.m_state = State.Stand;
         }
     }
     else
     {
         state.m_state = State.Stand;
     }
 }
コード例 #4
0
        private void FallCheck(ControlProperty control, StateProperty state)
        {
            if (!control.m_ground)
            {
                control.m_fallTimer += Time.deltaTime;

                if (!state.HasState(State.Fall))
                {
                    if (control.m_fallTimer > 0.1f && control.m_fallTimer < 0.6f)
                    {
                        state.m_state = State.Jump;
                    }
                    else
                    {
                        state.m_state = State.Fall;
                    }
                }
            }
            else
            {
                control.m_fallTimer = 0f;
            }
        }
コード例 #5
0
        private void JumpRunCheck(ControlProperty control, StateProperty state, InputProperty input)
        {
            if (control.m_jumpDelay > 0f)
            {
                control.m_jumpDelay -= Time.deltaTime;
            }

            if (state.m_lastState == State.Stand &&
                !InputUtils.ValidMove(new Vector2(control.m_rawDirection.x, control.m_rawDirection.z)) &&
                !control.m_idle)
            {
                control.m_run = false;
            }

            if (input.JumpWasPressed)
            {
                control.m_jumpTimer = 0f;
            }

            if (input.Jump)
            {
                if (control.m_jumpTimer > 0.4f)
                {
                    control.m_run      = true;
                    control.m_runTimer = 1f;
                }
                control.m_jumpTimer += Time.deltaTime;
            }
            else
            {
                if (control.m_runTimer >= 0)
                {
                    control.m_runTimer -= Time.deltaTime;
                }
                else
                {
                    control.m_runTimer = 0;
                    if (!control.m_idle)
                    {
                        control.m_run = false;
                    }
                }
            }

            if (input.JumpWasReleaseed)
            {
                if (control.m_jumpTimer <= 0.8f)
                {
                    control.m_jump = true;

                    if (control.m_jumpDelay <= 0f && !state.HasState(State.Jump) && !state.HasState(State.Fall))
                    {
                        control.m_fallTimer       -= 0.4f;
                        control.m_jumpDelay        = 0.8f;
                        control.m_groundCheckDelay = 0.1f;
                        state.m_state = State.Jump;
                    }
                }
            }
            else
            {
                control.m_jump = false;
            }
        }
コード例 #6
0
 public static bool HasState(this StateProperty state, State stateToCheck)
 {
     return((state.m_state & stateToCheck) == stateToCheck);
 }