void Update() { _idleForce = idleForce; // a two player version cannot be implemented at this point // because there are places in the scripts where the compiler looks for // objects named "Body", assuming there is only one such object. // To implement 2 players, we need to make sure we are not looking for objects named "Body" because we'll find 2. float LX = Input.GetAxis("Player 0 left X"); float LY = Input.GetAxis("Player 0 left Y"); float RX = Input.GetAxis("Player 0 right X"); float RY = Input.GetAxis("Player 0 right Y"); // idle cycle for inactive bodyparts float rotZDelta = GameObject.Find("Body").GetComponent <RotationInfo>().rotationZDelta; if (Mathf.Abs(rotZDelta) < 20) { float threshold = 0.6f; // don't play idlecycle on limbs that are functioning // bool fl: should you play idle on FL? bool fl = (Mathf.Abs(LX) + Mathf.Abs(LY) > threshold) ? false : true; bool fr = (Mathf.Abs(LX) + Mathf.Abs(LY) > threshold) ? false : true; bool bl = (Mathf.Abs(RX) + Mathf.Abs(RY) > threshold) ? false : true; bool br = (Mathf.Abs(RX) + Mathf.Abs(RY) > threshold) ? false : true; // if something has been pressed, deactivate idle until nothing has been pressed // idle for each leg depending on axes // idle cycle for all four legs IdleCycle(fl, fr, bl, br); } // =====================================input!!! // ============for charging jumps and rolls // if both joysticks are tilted the same way if (LX * RX > 0 && (Mathf.Abs(LX) > 0.5f || Mathf.Abs(RX) > 0.5f)) { jumpCharge += -chargeSpeed * (LX + RX) * Time.deltaTime; if (LX < 0) { chargeDirection = ChargeDirections.Right; } else { chargeDirection = ChargeDirections.Left; } print(chargeDirection.ToString()); } else if (LY * RY > 0 && (Mathf.Abs(LY) > 0.5f || Mathf.Abs(RY) > 0.5f)) { jumpCharge += chargeSpeed * (LY + RY); if (LY < 0) { chargeDirection = ChargeDirections.Back; } else { chargeDirection = ChargeDirections.Forward; } print(chargeDirection.ToString()); } else { Discharge(); } // clamp charge so we don't get astronaut dog jumpCharge = Mathf.Clamp(jumpCharge, -maxChargeBonus, maxChargeBonus); // which means LX * RX > 0 // or LY * RY > 0 // then increase the jumpCharge until the max amount. // else, discharge it. // =====================================left joystick!!! // tricepses if (Mathf.Abs(LY) < 0.5f) { // ===================================== left joystick: horizontal axis !!! // ============== leg: front left // when left controller going left, LX<0 so: // extend triceps = contract limb ExtendMuscle(legs[0], Muscles.Triceps, -LX); // extend triceps = extend biceps if (legs[0].GetTricepsLength() < 0.35f) { ExtendMuscle(legs[0], Muscles.Biceps, LX); } else { ExtendMuscle(legs[0], Muscles.Biceps, -LX); } if (LX < 0) { ExtendMuscle(legs[0], Muscles.Chest, -LX); } // ============== leg: front right // contract triceps = extend limb ContractMuscle(legs[1], Muscles.Triceps, -LX); // contract triceps = contract biceps // at the end of the contraction, we actually want to extend, just before we switch legs. if (legs[1].GetTricepsLength() < 0.35f) { ExtendMuscle(legs[1], Muscles.Biceps, -LX); } else { ContractMuscle(legs[1], Muscles.Biceps, -LX); } if (LX > 0) { ExtendMuscle(legs[1], Muscles.Chest, LX); } // contract biceps = idle other leg so we have some height :) if (LX < 0) { IdleLeg(0); } else if (LX > 0) { IdleLeg(1); } } else { // ===================================== left joystick: vertical axis! !!! // contract triceps = extend limb ContractMuscle(legs[0], Muscles.Triceps, LY); if (LY > 0) { ExtendMuscle(legs[0], Muscles.Biceps, LY); } else { ExtendMuscle(legs[0], Muscles.Biceps, -LY); } //ContractMuscle (legs[0], Muscles.Triceps, Mathf.Clamp(LY, -1, 0) - Mathf.Clamp(LX, -1, 0)); // same as above ContractMuscle(legs[1], Muscles.Triceps, LY); //ContractMuscle (legs[1], Muscles.Triceps, Mathf.Clamp(LY, -1, 0) + Mathf.Clamp(LX, 0, 1)); if (LY > 0) { ExtendMuscle(legs[1], Muscles.Biceps, LY); } else { ExtendMuscle(legs[1], Muscles.Biceps, -LY); } } // =====================================right joystick!!! if (Mathf.Abs(RY) < 0.5f) { // ===================================== right joystick: horizontal !!! ExtendMuscle(legs[2], Muscles.Triceps, -RX); if (legs[2].GetTricepsLength() < 0.35f) { ExtendMuscle(legs[2], Muscles.Biceps, RX); } else { ExtendMuscle(legs[2], Muscles.Biceps, -RX); } if (RX < 0) { ExtendMuscle(legs[2], Muscles.Chest, -RX); } ContractMuscle(legs[3], Muscles.Triceps, -RX); if (legs[3].GetTricepsLength() < 0.35f) { ExtendMuscle(legs[3], Muscles.Biceps, -RX); } else { ContractMuscle(legs[3], Muscles.Biceps, -RX); } if (RX > 0) { ExtendMuscle(legs[3], Muscles.Chest, RX); } // contract biceps = idle other leg so we have some height if (RX < 0) { IdleLeg(2); } else if (RX > 0) { IdleLeg(3); } } else { // ===================================== right joystick: vertical!!! ContractMuscle(legs[2], Muscles.Triceps, RY); ExtendMuscle(legs[2], Muscles.Biceps, RY); ContractMuscle(legs[3], Muscles.Triceps, RY); ExtendMuscle(legs[3], Muscles.Biceps, RY); } // bicepses // every time we want to contract a triceps // (expand the limb in pointing pos), we want to have the biceps contracted, // and only in the last moments expand it. // every time we want to expand a triceps (bring limb back) // we want a heavily expanded biceps (for pushing into ground) // and that's why we put the code between the tricepses. // ============================ jump charge elimination // if jumpcharge is positive, we only use it to get up on the back legs // if it is negative, we only use it to jump forward. // if we move in the opposite direction, we discharge the jumpcharge in the correct direction. // otherwise we let it slowly discharge. // ======== check if we move in opposite direction // if both joysticks are tilted the same way if (LX * RX > 0 && (Mathf.Abs(LX) > 0.5f || Mathf.Abs(RX) > 0.5f)) { // we know that we are moving seriously if (chargeDirection == ChargeDirections.Left) { // turn = force to the chest (maybe) } else if (chargeDirection == ChargeDirections.Right) { // turn = force to the chest (maybe) } } else if (LY * RY > 0 && (Mathf.Abs(LY) > 0.5f || Mathf.Abs(RY) > 0.5f)) { jumpCharge += chargeSpeed * (LY + RY); if (LY < 0) { chargeDirection = ChargeDirections.Back; } else { chargeDirection = ChargeDirections.Forward; } } else { Discharge(); } if (jumpCharge > 0) { if (LY < 0 && RY < 0) { // up on 2 back legs //print ("we're on the back legs"); } } else if (jumpCharge < 0) { if (LY > 0 && RY > 0) { // violent jump backward //print ("we're violently jumping forward now"); } } }
void Update() { _idleForce = idleForce; // a two player version cannot be implemented at this point // because there are places in the scripts where the compiler looks for // objects named "Body", assuming there is only one such object. // To implement 2 players, we need to make sure we are not looking for objects named "Body" because we'll find 2. float LX = Input.GetAxis("Player 0 left X"); float LY = Input.GetAxis("Player 0 left Y"); float RX = Input.GetAxis("Player 0 right X"); float RY = Input.GetAxis("Player 0 right Y"); // idle cycle for inactive bodyparts float rotZDelta = GameObject.Find("Body").GetComponent<RotationInfo>().rotationZDelta; if (Mathf.Abs(rotZDelta) < 20) { float threshold = 0.6f; // don't play idlecycle on limbs that are functioning // bool fl: should you play idle on FL? bool fl = (Mathf.Abs(LX) + Mathf.Abs(LY) > threshold) ? false : true; bool fr = (Mathf.Abs(LX) + Mathf.Abs(LY) > threshold) ? false : true; bool bl = (Mathf.Abs(RX) + Mathf.Abs(RY) > threshold) ? false : true; bool br = (Mathf.Abs(RX) + Mathf.Abs(RY) > threshold) ? false : true; // if something has been pressed, deactivate idle until nothing has been pressed // idle for each leg depending on axes // idle cycle for all four legs IdleCycle(fl, fr, bl, br); } // =====================================input!!! // ============for charging jumps and rolls // if both joysticks are tilted the same way if (LX * RX > 0 && (Mathf.Abs(LX) > 0.5f || Mathf.Abs(RX) > 0.5f)) { jumpCharge += -chargeSpeed * (LX + RX) * Time.deltaTime; if (LX < 0) chargeDirection = ChargeDirections.Right; else chargeDirection = ChargeDirections.Left; print (chargeDirection.ToString()); } else if (LY * RY > 0 && (Mathf.Abs(LY) > 0.5f || Mathf.Abs(RY) > 0.5f)) { jumpCharge += chargeSpeed * (LY + RY); if (LY < 0) chargeDirection = ChargeDirections.Back; else chargeDirection = ChargeDirections.Forward; print (chargeDirection.ToString()); } else { Discharge(); } // clamp charge so we don't get astronaut dog jumpCharge = Mathf.Clamp(jumpCharge, -maxChargeBonus, maxChargeBonus); // which means LX * RX > 0 // or LY * RY > 0 // then increase the jumpCharge until the max amount. // else, discharge it. // =====================================left joystick!!! // tricepses if (Mathf.Abs(LY) < 0.5f) { // ===================================== left joystick: horizontal axis !!! // ============== leg: front left // when left controller going left, LX<0 so: // extend triceps = contract limb ExtendMuscle (legs[0], Muscles.Triceps, -LX); // extend triceps = extend biceps if (legs[0].GetTricepsLength() < 0.35f) { ExtendMuscle (legs[0], Muscles.Biceps, LX); } else { ExtendMuscle (legs[0], Muscles.Biceps, -LX); } if (LX < 0) ExtendMuscle(legs[0], Muscles.Chest, -LX); // ============== leg: front right // contract triceps = extend limb ContractMuscle (legs[1], Muscles.Triceps, -LX); // contract triceps = contract biceps // at the end of the contraction, we actually want to extend, just before we switch legs. if (legs[1].GetTricepsLength() < 0.35f) { ExtendMuscle (legs[1], Muscles.Biceps, -LX); } else { ContractMuscle (legs[1], Muscles.Biceps, -LX); } if (LX > 0) ExtendMuscle(legs[1], Muscles.Chest, LX); // contract biceps = idle other leg so we have some height :) if (LX < 0) IdleLeg (0); else if (LX > 0) IdleLeg (1); } else { // ===================================== left joystick: vertical axis! !!! // contract triceps = extend limb ContractMuscle (legs[0], Muscles.Triceps, LY); if (LY > 0) ExtendMuscle (legs[0], Muscles.Biceps, LY); else ExtendMuscle (legs[0], Muscles.Biceps, -LY); //ContractMuscle (legs[0], Muscles.Triceps, Mathf.Clamp(LY, -1, 0) - Mathf.Clamp(LX, -1, 0)); // same as above ContractMuscle (legs[1], Muscles.Triceps, LY); //ContractMuscle (legs[1], Muscles.Triceps, Mathf.Clamp(LY, -1, 0) + Mathf.Clamp(LX, 0, 1)); if (LY > 0) ExtendMuscle (legs[1], Muscles.Biceps, LY); else ExtendMuscle (legs[1], Muscles.Biceps, -LY); } // =====================================right joystick!!! if (Mathf.Abs(RY) < 0.5f) { // ===================================== right joystick: horizontal !!! ExtendMuscle (legs[2], Muscles.Triceps, -RX); if (legs[2].GetTricepsLength() < 0.35f) { ExtendMuscle (legs[2], Muscles.Biceps, RX); } else { ExtendMuscle (legs[2], Muscles.Biceps, -RX); } if (RX < 0) ExtendMuscle(legs[2], Muscles.Chest, -RX); ContractMuscle (legs[3], Muscles.Triceps, -RX); if (legs[3].GetTricepsLength() < 0.35f) { ExtendMuscle (legs[3], Muscles.Biceps, -RX); } else { ContractMuscle (legs[3], Muscles.Biceps, -RX); } if (RX > 0) ExtendMuscle(legs[3], Muscles.Chest, RX); // contract biceps = idle other leg so we have some height if (RX < 0) IdleLeg (2); else if (RX > 0) IdleLeg (3); } else { // ===================================== right joystick: vertical!!! ContractMuscle (legs[2], Muscles.Triceps, RY); ExtendMuscle (legs[2], Muscles.Biceps, RY); ContractMuscle (legs[3], Muscles.Triceps, RY); ExtendMuscle (legs[3], Muscles.Biceps, RY); } // bicepses // every time we want to contract a triceps // (expand the limb in pointing pos), we want to have the biceps contracted, // and only in the last moments expand it. // every time we want to expand a triceps (bring limb back) // we want a heavily expanded biceps (for pushing into ground) // and that's why we put the code between the tricepses. // ============================ jump charge elimination // if jumpcharge is positive, we only use it to get up on the back legs // if it is negative, we only use it to jump forward. // if we move in the opposite direction, we discharge the jumpcharge in the correct direction. // otherwise we let it slowly discharge. // ======== check if we move in opposite direction // if both joysticks are tilted the same way if (LX * RX > 0 && (Mathf.Abs(LX) > 0.5f || Mathf.Abs(RX) > 0.5f)) { // we know that we are moving seriously if (chargeDirection == ChargeDirections.Left) { // turn = force to the chest (maybe) } else if (chargeDirection == ChargeDirections.Right) { // turn = force to the chest (maybe) } } else if (LY * RY > 0 && (Mathf.Abs(LY) > 0.5f || Mathf.Abs(RY) > 0.5f)) { jumpCharge += chargeSpeed * (LY + RY); if (LY < 0) chargeDirection = ChargeDirections.Back; else chargeDirection = ChargeDirections.Forward; } else { Discharge(); } if (jumpCharge > 0) { if (LY < 0 && RY < 0) { // up on 2 back legs //print ("we're on the back legs"); } } else if (jumpCharge < 0) { if (LY > 0 && RY > 0) { // violent jump backward //print ("we're violently jumping forward now"); } } }