Beispiel #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        motor.Rotation(speedInfo.turnSpeed);

        if (!enemyHasFired && timeBetweenFire >= fireTimer) //fires a shell
        {
            //place bullet firing here
            GameObject ammoClone = Instantiate(ammunition, gameObject.GetComponent <TankData>().FirePoint.position, transform.rotation);
            ammoClone.tag = "Enemy";
            ammoClone.GetComponent <AIShell>().damageDealt = gameObject.GetComponent <TankData>().shellDamageValue;

            StartCoroutine("TimeUp");
            enemyHasFired = true;
        }

        else if (enemyHasFired && timeBetweenFire <= fireTimer)
        {
            StopCoroutine("TimeUp");
            fireTimer     = 0;
            enemyHasFired = false;
        }
    }
Beispiel #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        ObstacleAvoidance();
        AILife();
        switch (EnemyType)
        {
        case TypeofEnemy.Idle:
        {
            if (!avoiding)
            {
                Idle();
                SensedSomething();
            }
            if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            return;
        }

        case TypeofEnemy.Looping:
        {
            if (!avoiding)
            {
                TurningAndMovingAI();
                Looping();
                SensedSomething();
            }
            if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            return;
        }

        case TypeofEnemy.Retracing:
        {
            if (!avoiding)
            {
                TurningAndMovingAI();
                Retrace();
                SensedSomething();
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            return;
        }

        case TypeofEnemy.Lookout:
        {
            if (!avoiding)
            {
                LookoutAI();
                SensedSomething();
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            return;
        }

        case TypeofEnemy.Flee:
        {
            if (avoiding)
            {
                ObstacleAvoidance();
            }
            else if (!avoiding)
            {
                RunFATBOYRun();
            }
            return;
        }

        case TypeofEnemy.sawPlayer:
        {
            if (avoiding)
            {
                ObstacleAvoidance();
            }
            else if (!avoiding)
            {
                FoundYou();
            }
            return;
        }

        case TypeofEnemy.HeardASound:
        {
            if (!avoiding)
            {
                HeardSomething();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }
                else if (!sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = originalState_;
                }
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            return;
        }

        default:
        {
            Debug.Log("No/Invalid State Was Selected");
            break;
        }
        }
    }
Beispiel #3
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.W))
        {
            motor.Movement(speedInfo.moveForwardSpeed); //forward movement at normal speed
        }
        else if (Input.GetKey(KeyCode.S))
        {
            motor.Movement(-speedInfo.moveBackSpeed); //allows backward movement for slower speed
        }

        if (Input.GetKey(KeyCode.D))
        {
            motor.Rotation(speedInfo.turnSpeed); //turn clockwise
        }
        else if (Input.GetKey(KeyCode.A))
        {
            motor.Rotation(-speedInfo.turnSpeed); //turn counterclockwise
        }

        if (Input.GetKeyDown(KeyCode.Space) && !hasFired && timeBetweenFire >= fireTimer) //fires a shell
        {
            GameObject ammoClone = Instantiate(ammunition, gameObject.GetComponent <TankData>().FirePoint.position, transform.rotation);
            //Object.Instantiate<GameObject>(ammunition);
            //just this doesn't work at all either (mainly because I'm using a prefab that isn't in the world at all)
            //Object.Instantiate<GameObject>(ammunition, gameObject.GetComponent<TankData>().FirePoint.position, transform.rotation,
            //    gameObject.GetComponent<TankData>().FirePoint.parent);
            //this works HOWEVER any movement of my tank afterwards moves the shell as well
            //Object.Instantiate<GameObject>(ammunition, gameObject.GetComponent<TankData>().FirePoint.parent);
            //this works as well HOWEVER any movement of my tank afterwards moves the shell as well
            //Object.Instantiate<GameObject>(ammunition, gameObject.GetComponent<TankData>().FirePoint.parent, true);
            //this does NOT work for some reason
            //Object.Instantiate<GameObject>(ammunition, gameObject.GetComponent<TankData>().FirePoint.position, transform.rotation);
            //this creates the object at position but does not set as child
            //ammunition.transform.SetParent(gameObject.GetComponent<TankData>().FirePoint, true);
            //this won't work and i can't figure out HOW to make it work
            if (gameObject.tag == "Player1")
            {
                ammoClone.tag = "Player1";
                ammoClone.GetComponent <PlayerShell>().damageDealt = gameObject.GetComponent <TankData>().shellDamageValue;
            }
            if (gameObject.tag == "Player2")
            {
                ammoClone.tag = "Player2";
                ammoClone.GetComponent <PlayerShell>().damageDealt = gameObject.GetComponent <TankData>().shellDamageValue;
            }
            StartCoroutine("TimeUp");
            hasFired = true;
        }

        else if (hasFired && timeBetweenFire <= fireTimer)
        {
            StopCoroutine("TimeUp");
            fireTimer = 0;
            hasFired  = false;
        }

        if (player.tag == ("Player1"))
        {
        }

        /* for future milestones
         * else if (player.tag == ("Player2"))
         * {
         *
         * }*/
    }
Beispiel #4
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (Input.GetKey(KeyCode.W))
        {
            motor.Movement(speedInfo.moveForwardSpeed); //forward movement at normal speed
            if (gameObject.GetComponent <PlayerMovement>().noisemaker != null && (gameObject.CompareTag("Player1") || gameObject.CompareTag("Player2")))
            {
                noisemaker.volume = Mathf.Max(gameObject.GetComponent <NoisemakerScript>().volume, moveVolume);
            }
        }
        else if (Input.GetKey(KeyCode.S))
        {
            motor.Movement(-speedInfo.moveBackSpeed); //allows backward movement for slower speed
            if (gameObject.GetComponent <PlayerMovement>().noisemaker != null && (gameObject.CompareTag("Player1") || gameObject.CompareTag("Player2")))
            {
                noisemaker.volume = Mathf.Max(gameObject.GetComponent <NoisemakerScript>().volume, moveVolume);
            }
        }

        if (Input.GetKey(KeyCode.D))
        {
            motor.Rotation(speedInfo.turnSpeed); //turn clockwise
            if (gameObject.GetComponent <PlayerMovement>().noisemaker != null && (gameObject.CompareTag("Player1") || gameObject.CompareTag("Player2")))
            {
                noisemaker.volume = Mathf.Max(gameObject.GetComponent <NoisemakerScript>().volume, turnVolume);
            }
        }
        else if (Input.GetKey(KeyCode.A))
        {
            motor.Rotation(-speedInfo.turnSpeed); //turn counterclockwise
            if (gameObject.GetComponent <PlayerMovement>().noisemaker != null && (gameObject.CompareTag("Player1") || gameObject.CompareTag("Player2")))
            {
                noisemaker.volume = Mathf.Max(gameObject.GetComponent <NoisemakerScript>().volume, turnVolume);
            }
        }

        if (Input.GetKeyDown(KeyCode.Space) && !hasFired && timeBetweenFire >= fireTimer) //fires a shell
        {
            GameObject ammoClone = Instantiate(ammunition, gameObject.GetComponent <TankData>().FirePoint.position, transform.rotation);

            if (gameObject.tag == "Player1")
            {
                ammoClone.tag = "Player1Shell";
                ammoClone.GetComponent <PlayerShell>().damageDealt = gameObject.GetComponent <TankData>().shellDamageValue;
            }
            if (gameObject.tag == "Player2")
            {
                ammoClone.tag = "Player2Shell";
                ammoClone.GetComponent <PlayerShell>().damageDealt = gameObject.GetComponent <TankData>().shellDamageValue;
            }
            StartCoroutine("TimeUp");
            hasFired = true;
        }

        else if (hasFired && timeBetweenFire <= fireTimer)
        {
            StopCoroutine("TimeUp");
            fireTimer = 0;
            hasFired  = false;
        }

        /*if (player.tag == ("Player1"))
         * {
         *
         * }
         * for future milestones
         * else if (player.tag == ("Player2"))
         * {
         *
         * }*/
    }
Beispiel #5
0
    // Update is called once per frame
    void FixedUpdate()
    {
        ObstacleAvoidance();
        AILife();
        switch (EnemyType)
        {
        case TypeofEnemy.Idle:
        {
            if (!avoiding)
            {
                Idle();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }

                if (sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = TypeofEnemy.HeardASound;
                }
            }
            if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            //if hearSomething
            //investigatesound
            return;
        }

        case TypeofEnemy.Looping:
        {
            if (!avoiding)
            {
                TurningAndMovingAI();
                Looping();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }
                if (sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = TypeofEnemy.HeardASound;
                }
            }
            if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            //if hearSomething
            //investigatesound
            return;
        }

        case TypeofEnemy.Retracing:
        {
            if (!avoiding)
            {
                TurningAndMovingAI();
                Retrace();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }
                if (sensing.CanSee(GameObject.FindWithTag("PowerUp")))         //if set to flee AI runs from it (can't figure it out at the moment)
                {
                    playerCharacter_ = gameObject.transform;
                    EnemyType        = TypeofEnemy.sawPlayer;
                }
                if (sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = TypeofEnemy.HeardASound;
                }
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            //if hearSomething
            //investigatesound
            return;
        }

        case TypeofEnemy.Lookout:
        {
            if (!avoiding)
            {
                LookoutAI();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }
                if (sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = TypeofEnemy.HeardASound;
                }
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            //if hearSomething
            //investigatesound
            return;
        }

        case TypeofEnemy.Flee:
        {
            if (avoiding)
            {
                ObstacleAvoidance();
            }
            else if (!avoiding)
            {
                RunFATBOYRun();
            }
            return;
        }

        case TypeofEnemy.sawPlayer:
        {
            if (avoiding)
            {
                ObstacleAvoidance();
            }
            else if (!avoiding)
            {
                FoundYou();
            }
            return;
        }

        case TypeofEnemy.HeardASound:
        {
            if (!avoiding)
            {
                HeardSomething();
                if (sensing.CanSee(GameManagement.instance.player1))
                {
                    playerCharacter_ = GameManagement.instance.player1.transform;
                    EnemyType        = SwitchTo;
                }
                else if (!sensing.CanHear(GameManagement.instance.player1))
                {
                    EnemyType = originalState_;
                }
            }
            else if (avoiding)
            {
                if (EnemyType == originalState_)
                {
                    avoiding = false;
                    motor_.Rotation(tankInfo_.turnSpeed);
                    return;
                }
                else
                {
                    ObstacleAvoidance();
                }
            }
            //if hearSomething
            //investigatesound
            return;
        }

        default:
        {
            Debug.Log("No/Invalid State Was Selected");
            break;
        }
        }
    }
Beispiel #6
0
 // Update is called once per frame
 void Update()
 {
     motor.Movement(speedInfo.moveForwardSpeed);
     motor.Rotation(speedInfo.turnSpeed);
 }