Ejemplo 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;
        }
    }
Ejemplo 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();
         }
     }
 }