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; } } }
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; } }
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; } }
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); }