Exemplo n.º 1
0
        private void Update()
        {
            if (GameManager.i.isPaused)
            {
                return;
            }

            if (Input.GetAxis("Horizontal") > 0)
            {
                artileryCommander.MoveArtileryClockwise();
            }
            if (Input.GetAxis("Horizontal") < 0)
            {
                artileryCommander.MoveArtileryCounterClockwise();
            }
            if (Input.GetAxis("Vertical") > 0)
            {
                shieldCommander.MoveShieldClockwise();
            }
            if (Input.GetAxis("Vertical") < 0)
            {
                shieldCommander.MoveShieldCounterClockwise();
            }
            if (Input.GetKeyDown(KeyCode.Space))
            {
                artileryCommander.HoldFire();
            }
            if (Input.GetKeyUp(KeyCode.Space))
            {
                artileryCommander.ReleaseFire();
            }
        }
Exemplo n.º 2
0
        private void AimIfNeeded()
        {
            const float aimThreshold = 5f;

            if (target == null)
            {
                return;
            }
            targetDirection = (target.transform.position - transform.position).normalized;
            aim             = Vector3.Dot(artileryCommander.aimDirection * 10, targetDirection.Value * 10);
            aimed           = aim >= aimQualifier;
            if (aimed)
            {
                return;
            }

            if (recentAim != null)
            {
                if (aim > 0 && recentAim.Value > 0)            // gun is facing to target
                {
                    if (recentAim.Value - aim >= aimThreshold) // bad aim direction. Toggle
                    {
                        aimCW = !aimCW;
                    }
                }
            }
            if (aimCW)
            {
                artileryCommander.MoveArtileryClockwise();
            }
            else
            {
                artileryCommander.MoveArtileryCounterClockwise();
            }

            if (Mathf.Abs(aimDiff) >= aimThreshold)
            {
                recentAim = Vector3.Dot(artileryCommander.aimDirection * 10, targetDirection.Value * 10);
            }
        }