Exemplo n.º 1
0
        private void DirectionCheck(ControlProperty control, InputProperty input)
        {
            control.m_rawDirection = new Vector3(input.Move.x, 0, input.Move.y);

            if (InputUtils.ValidMove(input.Move))
            {
                control.m_direction = control.m_rawDirection.normalized;
            }

            if (!control.m_idle)
            {
                control.m_lookDirection = control.m_direction + new Vector3(0, 0.2f, 0);
            }
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 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;
     }
 }
Exemplo n.º 4
0
        private void RunCycleRotateAnchor(ControlProperty control, BodyProperty body)
        {
            body[BodyPart.Anchor].BodyRigid.angularVelocity = Vector3.zero;

            Vector3 dir = new Vector3(control.m_direction.z, 0, -control.m_direction.x);

            if (!control.m_run)
            {
                if (body[BodyPart.Anchor].BodyRigid.velocity.magnitude < 3 * control.m_applyForce)
                {
                    body[BodyPart.Anchor].BodyRigid.maxAngularVelocity = 20;
                    body[BodyPart.Anchor].BodyRigid.angularVelocity    = dir * 20f;
                }
            }
            else
            {
                if (body[BodyPart.Anchor].BodyRigid.velocity.magnitude < 4 * control.m_applyForce)
                {
                    body[BodyPart.Anchor].BodyRigid.maxAngularVelocity = 60f;
                    body[BodyPart.Anchor].BodyRigid.angularVelocity    = dir * 60f;
                }
            }
        }
Exemplo n.º 5
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;
            }
        }
Exemplo n.º 6
0
        private void GroundCheck(ControlProperty control, BodyProperty body)
        {
            bool ground = body[BodyPart.LeftKnee].BodyCollider.m_onGround ||
                          body[BodyPart.RightKnee].BodyCollider.m_onGround ||
                          body[BodyPart.Anchor].BodyCollider.m_onGround;

            if (ground)
            {
                if (control.m_groundCheckDelay <= 0f)
                {
                    control.m_ground = true;
                }
                else
                {
                    control.m_ground            = false;
                    control.m_groundCheckDelay -= Time.deltaTime;
                }
            }
            else
            {
                control.m_ground = false;
            }
        }
Exemplo n.º 7
0
        private void RunCycleMainBody(ControlProperty control, MovementProperty movement, BodyProperty body)
        {
            if (control.m_run)
            {
                movement.m_runForce = Mathf.Clamp(movement.m_runForce + Time.fixedDeltaTime, 0f, 1f);
            }
            else
            {
                movement.m_runForce = Mathf.Clamp(movement.m_runForce - Time.fixedDeltaTime, 0f, 1f);
            }

            body[BodyPart.Torso].BodyRigid.AddForce(
                (MovementProperty.RunVecForce10 + 0.3f * control.m_direction * movement.m_runForce) * control.m_applyForce,
                ForceMode.VelocityChange);
            body[BodyPart.Hip].BodyRigid.AddForce(
                (-MovementProperty.RunVecForce5 + 0.3f * control.m_direction * movement.m_runForce) * control.m_applyForce,
                ForceMode.VelocityChange);
            body[BodyPart.Anchor].BodyRigid.AddForce(-MovementProperty.RunVecForce5 * control.m_applyForce, ForceMode.VelocityChange);

            body[BodyPart.Anchor].BodyRigid.AddForce(
                control.m_direction * control.m_applyForce, ForceMode.VelocityChange);

            ApplyForceUtils.AlignToVector(body[BodyPart.Head], body[BodyPart.Head].BodyTransform.forward,
                                          control.m_lookDirection, 0.1f, 5f * control.m_applyForce);
            ApplyForceUtils.AlignToVector(body[BodyPart.Head], body[BodyPart.Head].BodyTransform.up,
                                          Vector3.up, 0.1f, 5f * control.m_applyForce);

            ApplyForceUtils.AlignToVector(body[BodyPart.Torso], body[BodyPart.Torso].BodyTransform.forward,
                                          control.m_direction + Vector3.down, 0.1f, 10f * control.m_applyForce);
            ApplyForceUtils.AlignToVector(body[BodyPart.Torso], body[BodyPart.Torso].BodyTransform.up,
                                          Vector3.up, 0.1f, 10f * control.m_applyForce);

            ApplyForceUtils.AlignToVector(body[BodyPart.Hip], body[BodyPart.Hip].BodyTransform.forward,
                                          control.m_direction, 0.1f, 10f * control.m_applyForce);
            ApplyForceUtils.AlignToVector(body[BodyPart.Hip], body[BodyPart.Hip].BodyTransform.up,
                                          Vector3.up, 0.1f, 10f * control.m_applyForce);
        }
Exemplo n.º 8
0
        private void RunCyclePoseLeg(Side side, Pose pose, ControlProperty control, BodyProperty body)
        {
            Transform hip = body[BodyPart.Hip].BodyTransform;

            Transform sideLeg    = null;
            Transform unsideKnee = null;

            Rigidbody sideLegRig   = null;
            Rigidbody sideKneeRig  = null;
            Rigidbody unsideLegRig = null;

            switch (side)
            {
            case Side.Left:
                sideLeg      = body[BodyPart.LeftLeg].BodyTransform;
                unsideKnee   = body[BodyPart.RightKnee].BodyTransform;
                sideLegRig   = body[BodyPart.LeftLeg].BodyRigid;
                unsideLegRig = body[BodyPart.RightLeg].BodyRigid;
                sideKneeRig  = body[BodyPart.LeftKnee].BodyRigid;
                break;

            case Side.Right:
                sideLeg      = body[BodyPart.RightLeg].BodyTransform;
                unsideKnee   = body[BodyPart.LeftKnee].BodyTransform;
                sideLegRig   = body[BodyPart.RightLeg].BodyRigid;
                unsideLegRig = body[BodyPart.LeftLeg].BodyRigid;
                sideKneeRig  = body[BodyPart.RightKnee].BodyRigid;
                break;
            }

            switch (pose)
            {
            case Pose.Bent:
                ApplyForceUtils.AlignToVector(sideLegRig, -sideLeg.up, control.m_direction, 0.1f, 4f * control.m_applyForce);
                break;

            case Pose.Forward:
                if (control.m_run)
                {
                    ApplyForceUtils.AlignToVector(sideLegRig, -sideLeg.up, control.m_direction, 0.1f, 4f * control.m_applyForce);
                    sideLegRig.AddForce(-control.m_direction * 2f * control.m_applyForce);
                    sideKneeRig.AddForce(control.m_direction * 2f * control.m_applyForce);
                }
                else
                {
                    ApplyForceUtils.AlignToVector(sideLegRig, -sideLeg.up, control.m_direction - hip.up / 2, 0.1f, 4f * control.m_applyForce);
                    sideLegRig.AddForce(-control.m_direction * 2f, ForceMode.VelocityChange);
                    sideKneeRig.AddForce(control.m_direction * 2f, ForceMode.VelocityChange);
                }
                break;

            case Pose.Straight:
                ApplyForceUtils.AlignToVector(sideLegRig, sideLeg.up, Vector3.up, 0.1f, 4f * control.m_applyForce);
                sideLegRig.AddForce(hip.up * 2f * control.m_applyForce);
                sideKneeRig.AddForce(-hip.up * 2f * control.m_applyForce);
                break;

            case Pose.Behind:
                if (control.m_run)
                {
                    ApplyForceUtils.AlignToVector(sideLegRig, sideLeg.up, control.m_direction * 2f, 0.1f, 4f * control.m_applyForce);
                    body[BodyPart.Hip].BodyRigid.AddForce(MovementProperty.RunVecForce2 * control.m_applyForce, ForceMode.VelocityChange);
                    body[BodyPart.Anchor].BodyRigid.AddForce(-MovementProperty.RunVecForce2 * control.m_applyForce, ForceMode.VelocityChange);
                    sideKneeRig.AddForce(-body[BodyPart.Hip].BodyTransform.forward, ForceMode.VelocityChange);
                }
                else
                {
                    ApplyForceUtils.AlignToVector(sideLegRig, sideLeg.up, control.m_direction * 2f, 0.1f, 4f * control.m_applyForce);
                }
                break;
            }
        }
Exemplo n.º 9
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;
            }
        }