Example #1
0
    // 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
    }
Example #2
0
    // 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);
        }
    }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        playerIcon.GetComponent <Image>().sprite = playerRoles.helmets[(int)playerID];

        #region tank top rotation

        float newRotation = tankTop.transform.parent.transform.localEulerAngles.y;
        float test        = oldRotation - newRotation;

        tankTop.transform.Rotate(0f, test, 0f);

        if (InputManager.GetAxis("Right Stick Horizontal", playerID) != 0.0f)
        {
            tankTop.transform.Rotate(0f, (InputManager.GetAxis("Right Stick Horizontal", playerID) * gunnerRotateSpeed), 0f);
        }

        oldRotation = tankTop.transform.parent.transform.localEulerAngles.y;
        #endregion

        #region cannon angle
        //point cannon up
        if (InputManager.GetAxis("Left Stick Vertical", playerID) < 0)
        {
            if (angleCurrent < 100)
            {
                cannon.transform.RotateAround(cannonPivot.transform.position, cannonPivot.transform.right, -10 * Time.deltaTime);
                angleCurrent++;
            }
        }

        //point cannon down
        if (InputManager.GetAxis("Left Stick Vertical", playerID) > 0)
        {
            if (angleCurrent > -80)
            {
                cannon.transform.RotateAround(cannonPivot.transform.position, cannonPivot.transform.right, 10 * Time.deltaTime);
                angleCurrent--;
            }
        }
        #endregion

        #region main gun
        if (!reloading)
        {
            if (InputManager.GetAxis("Right Trigger", playerID) == 1)
            {
                // ToDo: ammotype needs to be implemented
                rockets.FireProjectile(selectedAmmo);
                reloading = true;

                playerRoles.DisplayPanel(anim, reloadPanel);
                launcher.GetComponent <LineRenderer>().enabled = false;
            }
        }

        else if (reloading)
        {
            activeReload.value += reloadSpeed;

            if (InputManager.GetAxis("Left Trigger", playerID) > 0 && !attemptedReload)
            {
                if (activeReload.value >= 0.45f && activeReload.value <= 0.55f)
                {
                    activeReload.value = 0;
                    reloading          = false;

                    playerRoles.HidePanel(anim, reloadPanel);
                    launcher.GetComponent <LineRenderer>().enabled = true;
                }
                else
                {
                    attemptedReload = true;
                }
            }
            if (activeReload.value >= 1) // adding half the width of line rail should make this dynamic
            {
                activeReload.value = 0;;
                reloading          = false;
                attemptedReload    = false;

                playerRoles.HidePanel(anim, reloadPanel);
                launcher.GetComponent <LineRenderer>().enabled = true;
            }
        }

        #endregion

        #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)
            {
                selectedAmmo = playerRoles.SelectAmmo(currentCombo, ammoCombos);
                abilityIcon.GetComponent <Image>().sprite = abilityIcons[selectedAmmo];
                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 Horizontal", playerID) == 1)
        {
            playerRoles.SwapToEngineer(this);
        }
        else if (InputManager.GetAxis("DPAD Vertical", playerID) == -1)
        {
            playerRoles.SwapToDriver(this);
        }
        else if (InputManager.GetAxis("DPAD Horizontal", playerID) == -1)
        {
            playerRoles.SwapToCommander(this);
        }
    }
Example #4
0
    // 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);
        }
    }
Example #5
0
    // Update is called once per frame
    void Update()
    {
        if (playerID != playerRoles.gunner)
        {
            return;
        }

        #region tank top rotation

        float newRotation = tankTop.transform.parent.transform.localEulerAngles.y;
        float test        = oldRotation - newRotation;

        tankTop.transform.Rotate(0f, test, 0f);

        if (InputManager.GetAxis("Right Stick Horizontal", playerID) != 0.0f)
        {
            tankTop.transform.Rotate(0f, (InputManager.GetAxis("Right Stick Horizontal", playerID) * gunnerRotateSpeed), 0f);
        }

        oldRotation = tankTop.transform.parent.transform.localEulerAngles.y;
        #endregion

        #region cannon angle
        //point cannon up
        if (InputManager.GetAxis("Left Stick Vertical", playerID) < 0)
        {
            if (angleCurrent < 100)
            {
                cannon.transform.RotateAround(cannonPivot.transform.position, cannonPivot.transform.right, -10 * Time.deltaTime);
                angleCurrent++;
            }
        }

        //point cannon down
        if (InputManager.GetAxis("Left Stick Vertical", playerID) > 0)
        {
            if (angleCurrent > -80)
            {
                cannon.transform.RotateAround(cannonPivot.transform.position, cannonPivot.transform.right, 10 * Time.deltaTime);
                angleCurrent--;
            }
        }
        #endregion

        #region main gun
        if (!reloading)
        {
            // draw line
            // ToDo: this should be a raycast to help see what it is aiming at
            Vector3 forward = launcher.transform.TransformDirection(Vector3.forward) * 20;
            Debug.DrawRay(launcher.transform.position, forward, Color.red);

            if (InputManager.GetAxis("Right Trigger", playerID) == 1)
            {
                // ToDo: ammotype needs to be implemented
                rockets.FireProjectile(selectedAmmo);
                reloading = true;

                playerRoles.DisplayPanel(anim, reloadPanel);
            }
        }

        else if (reloading)
        {
            marker.transform.Translate(Vector3.right * Time.deltaTime * reloadSpeed);

            if (InputManager.GetAxis("Left Trigger", playerID) > 0 && !attemptedReload)
            {
                if (marker.transform.position.x < sweetSpot.transform.position.x + 20.0f - 10 &&
                    marker.transform.position.x + 7.0f > sweetSpot.transform.position.x)
                {
                    marker.transform.position = initialPos;
                    reloading = false;

                    playerRoles.HidePanel(anim, reloadPanel);
                }
                else
                {
                    attemptedReload = true;
                    reloadSpeed     = 25;
                }
            }
            if (marker.transform.position.x >= (lineRail.transform.position.x + 109)) // adding half the width of line rail should make this dynamic
            {
                marker.transform.position = initialPos;
                reloading       = false;
                attemptedReload = false;
                reloadSpeed     = 50;

                playerRoles.HidePanel(anim, reloadPanel);
            }
        }

        #endregion

        #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)
            {
                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 Horizontal", playerID) == 1)
        {
            playerRoles.SwapToEngineer(this);
        }
        else if (InputManager.GetAxis("DPAD Vertical", playerID) == -1)
        {
            playerRoles.SwapToDriver(this);
        }
        else if (InputManager.GetAxis("DPAD Horizontal", playerID) == -1)
        {
            playerRoles.SwapToCommander(this);
        }
    }