void Update() { impactPoint = Vector3.zero; if (!isPlaying) { if (GameController.isPlaying) { isPlaying = true; if (PlayerData.player1Character == playerIndex.ToString()) { player = "One"; } else if (PlayerData.player2Character == playerIndex.ToString()) { player = "Two"; } else if (playerIndex.ToString() == "Jolly") { player = "One"; } else { player = "Two"; } } else { return; } } /* * if (fullyChargedBoost && !chargingBoost) * { * //if (controlScheme == 1) * { * rigidbody.AddForce(rigidbody.transform.forward * (chargeForce * (Time.deltaTime * boostTimerMax))); * } * * boostTimer += Time.deltaTime; * if (boostTimer >= boostTimerMax) * { * fullyChargedBoost = false; * chargeTimer = 0; * boostTimer = 0; * } * }*/ if (oar.isPaddling) { oar.paddlingTime += Time.deltaTime; if (oar.paddlingTime >= paddleTime) { oar.paddlingTime = 0; oar.isPaddling = false; } //return; } bool rightKey; bool leftKey; bool holdingForwardKey; bool holdingBackKey; bool releasingForwardKey; bool releasingBackKey; /* * if (reverseControls==true) * { * float joyStickDir = Input.GetAxis("Player_" + player + "_Joystick_Movement"); * if (Input.GetButton("Player_" + player + "_Paddle_Right") || joyStickDir > 0) * leftKey = true; * else * leftKey = false; * * if (Input.GetButton("Player_" + player + "_Paddle_Left") || joyStickDir < 0) * rightKey = true; * else * rightKey = false; * } * else*/ { float joyStickDir = Input.GetAxis("Player_" + player + "_Joystick_Horizontal"); if (Input.GetButton("Player_" + player + "_Paddle_Right") || joyStickDir > 0) { rightKey = true; } else { rightKey = false; } if (Input.GetButton("Player_" + player + "_Paddle_Left") || joyStickDir < 0) { leftKey = true; } else { leftKey = false; } } if (autoPaddle == true) { holdingForwardKey = false; holdingBackKey = false; if (Input.GetButton("Player_" + player + "_Paddle_Forward") || Input.GetButton("Player_" + player + "_Menu_Up")) { releasingForwardKey = true; } else { releasingForwardKey = false; } if (Input.GetButton("Player_" + player + "_Paddle_Back") || Input.GetButton("Player_" + player + "_Menu_Down")) { releasingBackKey = true; } else { releasingBackKey = false; } } else { holdingForwardKey = Input.GetButton("Player_" + player + "_Paddle_Forward"); if (Input.GetButtonUp("Player_" + player + "_Paddle_Forward") || Input.GetButtonUp("Player_" + player + "_Menu_Up")) { releasingForwardKey = true; } else { releasingForwardKey = false; } if (!holdingForwardKey && !releasingForwardKey) { holdingBackKey = Input.GetButton("Player_" + player + "_Paddle_Back"); if (Input.GetButtonUp("Player_" + player + "_Paddle_Back") || Input.GetButtonUp("Player_" + player + "_Menu_Down")) { releasingBackKey = true; } else { releasingBackKey = false; } } else { holdingBackKey = false; releasingBackKey = false; } } if (CanControl) { //if (controlScheme == 1) { if (leftKey) { if (!tiltedBoat) { tiltedBoat = true; PlayerData.boatTiltOffset = -boatTiltAngle; } else if (PlayerData.boatTiltOffset > 0) { PlayerData.boatTiltOffset = -boatTiltAngle; } //oar.onLeftSide = true; //oar.onRightSide = false; //if (!oar.onLeftSide) oar.SetRightSide(false); oar.SetLeftSide(true); Quaternion rot = characterModel.transform.localRotation; rot.z = .25f; characterModel.transform.localRotation = rot; impactPoint = oar.Paddle("Left"); //rigidbody.AddForceAtPosition(rigidbody.transform.forward * turnForwardForce, impactPoint); rigidbody.AddTorque(rigidbody.transform.up * -turnForwardForce); //rigidbody.AddRelativeForce(Vector3.right * sidePushForce); if (animator != null) { animator.SetFloat("Left/Right", 0.0f); } } else if (rightKey) { if (!tiltedBoat) { tiltedBoat = true; PlayerData.boatTiltOffset = boatTiltAngle; } else if (PlayerData.boatTiltOffset < 0) { PlayerData.boatTiltOffset = boatTiltAngle; } //oar.onLeftSide = false; //oar.onRightSide = true; //if (!oar.onRightSide) oar.SetRightSide(true); oar.SetLeftSide(false); impactPoint = oar.Paddle("Right"); //rigidbody.AddForceAtPosition(rigidbody.transform.forward * turnForwardForce, impactPoint); rigidbody.AddTorque(rigidbody.transform.up * turnForwardForce); //rigidbody.AddRelativeForce(Vector3.left * sidePushForce); Quaternion rot = characterModel.transform.localRotation; rot.z = -.25f; characterModel.transform.localRotation = rot; if (animator != null) { animator.SetFloat("Left/Right", 1.0f); } } else { if (tiltedBoat) { tiltedBoat = false; PlayerData.boatTilted = false; PlayerData.boatTiltOffset = 0; } oar.SetLeftSide(false); oar.SetRightSide(false); Quaternion rot = characterModel.transform.localRotation; rot.z = 0; characterModel.transform.localRotation = rot; //oar.onRightSide = false; //oar.onLeftSide = false; /* * if (oar.onLeftSide) * oar.SetLeftSide(false); * if (oar.onRightSide) * oar.SetRightSide(false); */ if (animator != null) { animator.SetFloat("Left/Right", 0.5f); } } if (!oar.isPaddling) { if (holdingForwardKey || holdingBackKey) { chargingBoost = true; if (chargeTimer < chargeTimerMax) { chargeTimer += Time.deltaTime; if (chargeTimer >= chargeTimerMax) { chargeTimer = chargeTimerMax; fullyChargedBoost = true; } } } if (releasingForwardKey) { onPaddleSwoshSound.Play(); if (animator != null) { animator.SetTrigger("Rowing"); } chargingBoost = false; fullyChargedBoost = false; /* * if (playerIndex.ToString() == "Jolly") * { * if (!oar.onLeftSide) * oar.SetLeftSide(true); * } * else * { * if (!oar.onRightSide) * oar.SetRightSide(true); * }*/ if (fullyChargedBoost) { impactPoint = oar.Paddle("Forward"); chargeForce = forwardForce; rigidbody.AddForce(rigidbody.transform.forward * (turnForwardForce * boostTurnMultiplier)); } else { chargeTimer = 0; boostTimer = 0; impactPoint = oar.Paddle("Forward"); //if (rigidbody.velocity.magnitude < maximumSpeed) { rigidbody.AddForce(rigidbody.transform.forward * forwardForce); } //rigidbody.AddForceAtPosition(rigidbody.transform.forward * turnForwardForce, impactPoint); //if (oar.onLeftSide) rigidbody.AddRelativeForce(Vector3.right * sidePushForce); //else if (oar.onRightSide) rigidbody.AddRelativeForce(Vector3.left * sidePushForce); } } else if (releasingBackKey) { onPaddleSwoshSound.Play(); if (animator != null) { animator.SetTrigger("Rowing"); } chargingBoost = false; fullyChargedBoost = false; /* * if (playerIndex.ToString() == "Jolly") * { * if (!oar.onLeftSide) * oar.SetLeftSide(true); * } * else * { * if (!oar.onRightSide) * oar.SetRightSide(true); * }*/ if (fullyChargedBoost) { impactPoint = oar.Paddle("Backward"); chargeForce = backwardForce; rigidbody.AddForce(-rigidbody.transform.forward * (turnBackwardForce * boostTurnMultiplier)); } else { chargeTimer = 0; boostTimer = 0; impactPoint = oar.Paddle("Backward"); rigidbody.AddForce(-rigidbody.transform.forward * backwardForce); //rigidbody.AddForceAtPosition(-rigidbody.transform.forward * turnBackwardForce, impactPoint); } } } } #region OldControlScheme /* * if (controlScheme == 2) * { * if (!oar.isPaddling && (oar.onLeftSide || oar.onRightSide)) * { * if (holdingForwardKey || holdingBackKey) * { * chargingBoost = true; * if (chargeTimer < chargeTimerMax) * { * chargeTimer += Time.deltaTime; * * if (chargeTimer >= chargeTimerMax) * { * chargeTimer = chargeTimerMax; * fullyChargedBoost = true; * } * } * } * * if (releasingForwardKey) * { * chargingBoost = false; * * if (fullyChargedBoost) * { * impactPoint = oar.Paddle("Forward"); * chargeForce = forwardForce; * * rigidbody.AddForceAtPosition(rigidbody.transform.forward * (turnForwardForce * boostTurnMultiplier), impactPoint); * } * else * { * chargeTimer = 0; * boostTimer = 0; * * impactPoint = oar.Paddle("Forward"); * * //if (rigidbody.velocity.magnitude < maximumSpeed) * { rigidbody.AddForce(rigidbody.transform.forward * forwardForce); } * rigidbody.AddForceAtPosition(rigidbody.transform.forward * turnForwardForce, impactPoint); * if (oar.onLeftSide) rigidbody.AddRelativeForce(Vector3.right * sidePushForce); * else if (oar.onRightSide) rigidbody.AddRelativeForce(Vector3.left * sidePushForce); * } * } * else if (releasingBackKey) * { * chargingBoost = false; * * if (fullyChargedBoost) * { * impactPoint = oar.Paddle("Backward"); * chargeForce = backwardForce; * rigidbody.AddForceAtPosition(-rigidbody.transform.forward * (turnBackwardForce * boostTurnMultiplier), impactPoint); * } * else * { * chargeTimer = 0; * boostTimer = 0; * * impactPoint = oar.Paddle("Backward"); * * rigidbody.AddForce(-rigidbody.transform.forward * backwardForce); * rigidbody.AddForceAtPosition(-rigidbody.transform.forward * turnBackwardForce, impactPoint); * } * } * } * * if (leftKey) * { * if (!oar.onLeftSide) * oar.SetLeftSide(true); * } * else * { * if (oar.onLeftSide) * oar.SetLeftSide(false); * } * * if (rightKey) * { * if (!oar.onRightSide) * oar.SetRightSide(true); * } * else * { * if (oar.onRightSide) * oar.SetRightSide(false); * } * } */ #endregion } }