// Update is called once per frame void Update() { playerIcon.GetComponent <Image>().sprite = playerRoles.helmets[(int)playerID]; // follow the tank Vector3 temp = follow.transform.position - oldTargetPosition; target.transform.Translate(temp, Space.World); // movement input if (InputManager.GetAxis("Left Stick Vertical", playerID) != 0.0f) { target.transform.Translate(new Vector3(1, 0, 1) * -InputManager.GetAxis("Left Stick Vertical", playerID) * translateSpeed * Time.deltaTime, Space.World); } if (InputManager.GetAxis("Left Stick Horizontal", playerID) != 0.0f) { target.transform.Translate(new Vector3(-1, 0, 1) * -InputManager.GetAxis("Left Stick Horizontal", playerID) * translateSpeed * Time.deltaTime, Space.World); } // update tank's old position oldTargetPosition = follow.transform.position; // update position of commander target int layerMask = 1 << 8; RaycastHit hit; Ray ray = new Ray(target.transform.position, Vector3.down); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask)) { reticle.transform.position = hit.point; } AdjustReticles(); // manage trigger input if (InputManager.GetAxis("Left Trigger", playerID) > 0) { Activate(); } else { UpdateGun(); Mark(); } // switch current mode #region weapon swapping if (InputManager.GetButtonDown("Left Bumper", playerID)) { // display the options when pushing left bumper playerRoles.DisplayPanel(anim, ammoPanel); currentCombo = new List <string>(); } else if (InputManager.GetButtonUp("Left Bumper", playerID) || currentCombo.Count == 4) { if (currentCombo.Count == 4) { selectedMode = playerRoles.SelectAmmo(currentCombo, ammoCombos); abilityIcon.GetComponent <Image>().sprite = abilityIcons[selectedMode]; currentCombo = new List <string>(); } // display the options when pushing left bumper playerRoles.HidePanel(anim, ammoPanel); playerRoles.ResetCombo(comboButtons); } if (InputManager.GetButton("Left Bumper", playerID)) { // Add buttons to the current combo if (InputManager.GetButtonDown("Button A", playerID)) { currentCombo.Add("Button A"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button B", playerID)) { currentCombo.Add("Button B"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button X", playerID)) { currentCombo.Add("Button X"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button Y", playerID)) { currentCombo.Add("Button Y"); playerRoles.DisplayCombo(currentCombo, comboButtons); } } #endregion if (InputManager.GetAxis("DPAD Vertical", playerID) == 1) { playerRoles.SwapToGunner(this); } else if (InputManager.GetAxis("DPAD Horizontal", playerID) == 1) { playerRoles.SwapToEngineer(this); } else if (InputManager.GetAxis("DPAD Vertical", playerID) == -1) { playerRoles.SwapToDriver(this); } }
// Update is called once per frame void Update() { if (playerID != inputMngr.GetComponent <PlayerRoles>().driver) { return; } if (selectedMode == 1) { if ((InputManager.GetAxis("Right Trigger", playerID) == 1 && InputManager.GetAxis("Left Trigger", playerID) == 1)) { flames.Emit(5); } } else if (selectedMode == 2) { //press and hold left trigger to launch harpoon if ((InputManager.GetAxis("Left Trigger", playerID) == 1)) { //if a harpoon is not currently out if (!harpoonOut) { LaunchHarpoon(); } } //release to destroy hook + release the hooked obj if (InputManager.GetAxis("Left Trigger", playerID) <= 0.5f) { //if the harpoon is out and has hooked something if (harpoonOut) { harpoonOut = false; if (harpoonClone) { harpoonClone.GetComponent <Harpoon>().ReleaseHook(); } } } //press b to initiate slam attack for the glorious union if (InputManager.GetButtonDown("Button B", playerID)) { harpoonClone.GetComponent <Harpoon>().SlamAttack(); } } else if (selectedMode == 0) { #region boost what a f*****g mess //driver's boost if (InputManager.GetAxis("Right Trigger", playerID) == 1 && InputManager.GetAxis("Left Trigger", playerID) == 1) //are the boost buttons being pressed? { if (BoostFrames > 0 && canBoost == true) //is there boost left, and is it on cooldown? { //then go fast speed = 10 * 2; rotateSpeed = hullRotateSpeed * 2; //but reduce the boost pool BoostFrames--; }//if else { speed = 10; rotateSpeed = hullRotateSpeed; } }//if else if (InputManager.GetAxis("Right Trigger", playerID) != 1 || InputManager.GetAxis("Left Trigger", playerID) != 1) { speed = 10; rotateSpeed = hullRotateSpeed; i++; if (i >= 3) { if (BoostFrames <= BoostTotal) { BoostFrames++; } i = 0; } } if (BoostFrames == 0) { canBoost = false; } if (canBoost == false) { if (BoostFrames >= boostCooldown) { canBoost = true; } } #endregion } #region driver controls //rotate clockwise if (InputManager.GetAxis("Left Stick Vertical", playerID) < 0 && InputManager.GetAxis("Right Stick Vertical", playerID) > 0) { Quaternion deltaRotation = Quaternion.Euler((new Vector3(0, 1, 0) * (rotateSpeed)) * Time.deltaTime); rb.MoveRotation(rb.rotation * deltaRotation); } //rotate counterclockwise if (InputManager.GetAxis("Left Stick Vertical", playerID) > 0 && InputManager.GetAxis("Right Stick Vertical", playerID) < 0) { Quaternion deltaRotation = Quaternion.Euler((new Vector3(0, -1, 0) * (rotateSpeed)) * Time.deltaTime); rb.MoveRotation(rb.rotation * deltaRotation); } //move forward if (InputManager.GetAxis("Left Stick Vertical", playerID) < 0 && InputManager.GetAxis("Right Stick Vertical", playerID) < 0) { rb.MovePosition(transform.position + transform.forward * Time.deltaTime * speed); } //move backward if (InputManager.GetAxis("Left Stick Vertical", playerID) > 0 && InputManager.GetAxis("Right Stick Vertical", playerID) > 0) { rb.MovePosition(transform.position + -transform.forward * Time.deltaTime * speed); } //left stick only if (InputManager.GetAxis("Left Stick Vertical", playerID) < 0 && InputManager.GetAxis("Right Stick Vertical", playerID) == 0) { rotateRigidBodyAroundPointBy(rb, rightTreadPivot.transform.position, rightTreadPivot.transform.up, (rotateSpeed * Time.deltaTime)); } if (InputManager.GetAxis("Left Stick Vertical", playerID) > 0 && InputManager.GetAxis("Right Stick Vertical", playerID) == 0) { rotateRigidBodyAroundPointBy(rb, rightTreadPivot.transform.position, rightTreadPivot.transform.up, -(rotateSpeed * Time.deltaTime)); } //right stick only if (InputManager.GetAxis("Left Stick Vertical", playerID) == 0 && InputManager.GetAxis("Right Stick Vertical", playerID) > 0) { rotateRigidBodyAroundPointBy(rb, leftTreadPivot.transform.position, leftTreadPivot.transform.up, (rotateSpeed * Time.deltaTime)); } if (InputManager.GetAxis("Left Stick Vertical", playerID) == 0 && InputManager.GetAxis("Right Stick Vertical", playerID) < 0) { rotateRigidBodyAroundPointBy(rb, leftTreadPivot.transform.position, leftTreadPivot.transform.up, -(rotateSpeed * Time.deltaTime)); } #endregion if (Input.GetKeyDown(KeyCode.U)) { flipTank(); } #region weapon swapping if (InputManager.GetButtonDown("Left Bumper", playerID)) { // display the options when pushing left bumper playerRoles.DisplayPanel(anim, ammoPanel); currentCombo = new List <string>(); } else if (InputManager.GetButtonUp("Left Bumper", playerID) || currentCombo.Count == 4) { if (currentCombo.Count == 4) { selectedMode = playerRoles.SelectAmmo(currentCombo, ammoCombos); currentCombo = new List <string>(); } // display the options when pushing left bumper playerRoles.HidePanel(anim, ammoPanel); playerRoles.ResetCombo(comboButtons); } if (InputManager.GetButton("Left Bumper", playerID)) { // Add buttons to the current combo if (InputManager.GetButtonDown("Button A", playerID)) { currentCombo.Add("Button A"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button B", playerID)) { currentCombo.Add("Button B"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button X", playerID)) { currentCombo.Add("Button X"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button Y", playerID)) { currentCombo.Add("Button Y"); playerRoles.DisplayCombo(currentCombo, comboButtons); } } #endregion #region role swapping if (InputManager.GetAxis("DPAD Vertical", playerID) == 1) { playerRoles.SwapToGunner(this); } else if (InputManager.GetAxis("DPAD Horizontal", playerID) == 1) { playerRoles.SwapToEngineer(this); } else if (InputManager.GetAxis("DPAD Horizontal", playerID) == -1) { playerRoles.SwapToCommander(this); } #endregion }
// Update is called once per frame void Update() { if (playerID != inputMngr.GetComponent <PlayerRoles>().engineer) { return; } if (amEngineer) { // Reticle follows the tank Vector3 follow = target.transform.position - oldTargetPosition; reticle.transform.Translate(follow, Space.World); oldTargetPosition = target.transform.position; // Hold to allow for Grenade aiming if (InputManager.GetAxis("Left Trigger", playerID) > 0) { reticle.SetActive(true); // sapBcks the reticle to tank position after pulling let tigger if (snapBack) { reticle.transform.position = (target.transform.position + new Vector3(0, 5.11f, 0)); snapBack = false; } // if (Vector3.Distance(reticle.transform.position, target.transform.position) < aimDistance) if (InputManager.GetAxis("Left Stick Vertical", playerID) != 0.0f) { reticle.transform.Translate(new Vector3(1, 0, 1) * -InputManager.GetAxis("Left Stick Vertical", playerID) * translateSpeed * Time.deltaTime, Space.World); // Prevents player from moving reticle past a certain distance from tank. There is probably a better way to do this if (Vector3.Distance(reticle.transform.position, target.transform.position) >= aimDistance) { reticle.transform.Translate(new Vector3(1, 0, 1) * InputManager.GetAxis("Left Stick Vertical", playerID) * translateSpeed * Time.deltaTime, Space.World); } } if (InputManager.GetAxis("Left Stick Horizontal", playerID) != 0.0f) { reticle.transform.Translate(new Vector3(-1, 0, 1) * -InputManager.GetAxis("Left Stick Horizontal", playerID) * translateSpeed * Time.deltaTime, Space.World); // Prevents player from moving reticle past a certain distance from tank. There is probably a better way to do this if (Vector3.Distance(reticle.transform.position, target.transform.position) >= aimDistance) { reticle.transform.Translate(new Vector3(-1, 0, 1) * InputManager.GetAxis("Left Stick Horizontal", playerID) * translateSpeed * Time.deltaTime, Space.World); } } if (InputManager.GetAxis("Right Trigger", playerID) > 0) { if (Time.time - timeLast > reloadTime) { ThrowGrenade(); timeLast = Time.time; } } } else { reticle.SetActive(false); snapBack = true; } } #region ammo swapping if (InputManager.GetButtonDown("Left Bumper", playerID)) { // display the options when pushing left bumper playerRoles.DisplayPanel(anim, ammoPanel); currentCombo = new List <string>(); } else if (InputManager.GetButtonUp("Left Bumper", playerID) || currentCombo.Count == 4) { if (currentCombo.Count == 4) { selectedAmmo = playerRoles.SelectAmmo(currentCombo, ammoCombos); currentCombo = new List <string>(); } // display the options when pushing left bumper playerRoles.HidePanel(anim, ammoPanel); playerRoles.ResetCombo(comboButtons); } if (InputManager.GetButton("Left Bumper", playerID)) { // Add buttons to the current combo if (InputManager.GetButtonDown("Button A", playerID)) { currentCombo.Add("Button A"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button B", playerID)) { currentCombo.Add("Button B"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button X", playerID)) { currentCombo.Add("Button X"); playerRoles.DisplayCombo(currentCombo, comboButtons); } else if (InputManager.GetButtonDown("Button Y", playerID)) { currentCombo.Add("Button Y"); playerRoles.DisplayCombo(currentCombo, comboButtons); } } #endregion if (InputManager.GetAxis("DPAD Vertical", playerID) == 1) { playerRoles.SwapToGunner(this); } else if (InputManager.GetAxis("DPAD Vertical", playerID) == -1) { playerRoles.SwapToDriver(this); } else if (InputManager.GetAxis("DPAD Horizontal", playerID) == -1) { playerRoles.SwapToCommander(this); } }