Exemplo n.º 1
0
    void ObstacleAvoidance()
    {
        // backup until the obstacle is no longer within range
        if (CanMove(data.moveSpeed) == false && avoidanceStage == 1)
        {
            motor.Backwards();
        }
        else if (CanMove(data.moveSpeed) == true && avoidanceStage == 1)
        {
            avoidanceStage = 2;
        }
        //rotate right until there's nothing infront of the tank
        RaycastHit hit;

        if (Physics.Raycast(transform.position, transform.forward, out hit, (data.moveSpeed / 2)) && avoidanceStage == 2)
        {
            motor.RotateRight();
        }
        else if (avoidanceStage == 2 && CanMove(data.moveSpeed))
        {
            avoidanceStage = 3;
        }
        // Move forward a few meters
        Vector3 avoidancePoint = transform.forward + new Vector3(0, 0, 4);

        if (Vector3.Distance(transform.position, avoidancePoint) > minDistance && avoidanceStage == 3)
        {
            motor.Forwards();
        }
        else if (Vector3.Distance(transform.position, avoidancePoint) <= minDistance && avoidanceStage == 3)
        {
            avoidanceStage = 1;
        }
    }
Exemplo n.º 2
0
 // Update is called once per frame
 void Update()
 {
     fire.shellDamage = data.shellDamage;
     // Countdown
     fire.timer -= Time.deltaTime;
     // Check if the player is pressing the forwards key
     if (Input.GetKey(forwards))
     {
         // Use the Forwards function on the TankMotor script
         motor.Forwards();
     }
     // Check if the player is pressing backwards key
     if (Input.GetKey(backwards))
     {
         // Use the Backwards function on the TankMotor script
         motor.Backwards();
     }
     // Check if the player is pressing rotate left key
     if (Input.GetKey(rotateLeft))
     {
         // Use the RotateLeft function on the TankMotor script
         motor.RotateLeft();
     }
     // Check if the player is pressing rotate right key
     if (Input.GetKey(rotateRight))
     {
         // Use the RotateRight function on the TankMotor script
         motor.RotateRight();
     }
     // Check if the count down is less than or equal to 0
     if (fire.timer <= 0)
     {
         // Check if the player is pressing space
         if (Input.GetKeyDown(shootShell))
         {
             // Use the Fire function on the Shoot script
             fire.Fire();
         }
     }
 }
Exemplo n.º 3
0
    void Avoidance(string previousState)
    {
        ChangeState("Avoiding");
        // Begin the first part of avoiding
        if (avoidanceStage == 1)
        {
            // Rotate to the left for a designer set amount of time
            stageTimer = resetTimer;
            motor.RotateLeft();

            // Go to the next stage
            if (stageTimer <= 0)
            {
                avoidanceStage = 2;
            }
        }
        if (avoidanceStage == 2)
        {
            // Move forward for a designer set amount of time
            stageTimer      = resetTimer;
            motor.moveSpeed = restoreSpeed;
            motor.MoveForward();
            if (stageTimer <= 0)
            {
                avoidanceStage = 3;
            }
        }
        if (avoidanceStage == 3)
        {
            // Rotate to the right for set amount of time
            stageTimer = resetTimer;
            motor.RotateRight();
            if (stageTimer <= 0)
            {
                avoidanceStage = 0;
                ChangeState(previousState);
            }
        }
    }
Exemplo n.º 4
0
 // Update is called once per frame
 void Update()
 {
     // Countdown
     fire.timer -= Time.deltaTime;
     // Check if the player is pressing w or the up arrow
     if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow))
     {
         // Use the MoveForward function on the TankMotor script
         motor.MoveForward();
     }
     // Check if the player is pressing s or the down arrow
     if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow))
     {
         // Use the MoveBackwards function on the TankMotor script
         motor.MoveBackwards();
     }
     // Check if the player is pressing a or the left arrow
     if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow))
     {
         // Use the RotateLeft function on the TankMotor script
         motor.RotateLeft();
     }
     // Check if the player is pressing d or the right arrow
     if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow))
     {
         // Use the RotateRight function on the TankMotor script
         motor.RotateRight();
     }
     // Check if the count down is less than or equal to 0
     if (fire.timer <= 0)
     {
         // Check if the player is pressing space
         if (Input.GetKeyDown(KeyCode.Space))
         {
             // Use the Fire function on the Shoot script
             fire.Fire();
         }
     }
 }