Example #1
0
    public void ChaseAndFire(GameObject target)
    {
        motor.RotateTowards(target.transform.position, data.turnSpeed);

        if (controller.canMove((data.moveSpeed * 0.5f)))
        {
            motor.Move(data.moveSpeed * 0.5f);
        }
        else
        {
            controller.avoidStage = 1;
        }
        if (Time.time > lastEventTime + timerDelay)
        {
            lastEventTime = Time.time;
            shooter.shoot();
        }
    }
Example #2
0
 public void Chase(GameObject target)
 {
     if (motor.RotateTowards(target.transform.position, data.turnSpeed))
     {
         //Do Nothing
     }
     else
     {
         if (Vector3.SqrMagnitude(transform.position - target.transform.position) >= (closeEnough * closeEnough))
         {
             motor.Move(data.moveSpeed);
         }
         else
         {
             if (Time.time > lastEventTime + timerDelay)
             {
                 lastEventTime = Time.time;
                 shooter.shoot();
             }
         }
     }
 }
Example #3
0
    // Update is called once per frame
    void Update()
    {
        switch (inputScheme)
        {
        //Arrow Key Movement
        case InputScheme.arrowKeys:
            //Handling Movement
            if (Input.GetKey(KeyCode.UpArrow))     //Move Up
            {
                motor.Move(data.moveSpeed);
            }
            else if (Input.GetKey(KeyCode.DownArrow))     //Move Back
            {
                motor.Move(-data.moveSpeed);
            }
            else
            {
                motor.Move(0);
            }

            //Handling Rotation
            if (Input.GetKey(KeyCode.RightArrow))     //Move Right
            {
                motor.Rotate(-data.turnSpeed);
            }
            else if (Input.GetKey(KeyCode.LeftArrow))     //Move Left
            {
                motor.Rotate(data.turnSpeed);
            }
            //Handle Shooting
            if (Input.GetKeyDown(KeyCode.KeypadEnter))     //Shoot
            {
                if (Time.time >= lastEventTime + timerDelay)
                {
                    shooter.shoot();
                    lastEventTime = Time.time;
                }
            }

            break;

        //WASD Movement
        case InputScheme.WASD:

            //Handling Movement
            if (Input.GetKey(KeyCode.W))     //Move Up
            {
                motor.Move(data.moveSpeed);
            }
            else if (Input.GetKey(KeyCode.S))     //Move Back
            {
                motor.Move(-data.moveSpeed);
            }
            else
            {
                motor.Move(0);
            }

            //Handling Rotation
            if (Input.GetKey(KeyCode.A))     // Move Right
            {
                motor.Rotate(-data.turnSpeed);
            }
            else if (Input.GetKey(KeyCode.D))     //Move Left
            {
                motor.Rotate(data.turnSpeed);
            }

            //Handle Shooting
            if (Input.GetKey(KeyCode.Space))     //Shoot
            {
                if (Time.time >= lastEventTime + timerDelay)
                {
                    shooter.shoot();
                    lastEventTime = Time.time;
                }
            }

            break;


        default:
            Debug.LogError("No input scheme selected.");
            break;
        }
    }
Example #4
0
    public void Patrol()
    {
        //TODO: We need to so see if we are already at the waypoint

        //If we are not rotated to face the waypoint, turn to face it
        if (motor.RotateTowards(waypoints[currentWaypoint].transform.position, data.turnSpeed))
        {
            //Do Nothing
        }
        else
        {
            motor.Move(data.moveSpeed);
        }
        //If we have arrived at the waypoint, advance to next way point

        //If the AI is to move along its patrol once
        if (loopType == LoopType.stop)
        {
            if (currentWaypoint < (waypoints.Length - 1))
            {
                if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough))
                {
                    currentWaypoint++;
                }
            }
        }


        //If the AI is to loop its patrol
        else if (loopType == LoopType.loop)
        {
            if (Vector3.SqrMagnitude(waypoints[currentWaypoint].transform.position - transform.position) < closeEnough)
            {
                if (currentWaypoint < waypoints.Length - 1) // IF the current waypoint is not the last in the array. go to the next waypoint
                {
                    currentWaypoint++;
                }
                else
                {
                    currentWaypoint = 0; //If the current waypoint is the last in the array go to the first waypoint in the array
                }
            }



            else if (loopType == LoopType.pingpong)
            {
                if (isLoopingForward == true)
                {
                    if (isNotAtFinalWaypoint)
                    {
                        if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough))
                        {
                            currentWaypoint++;
                        }
                        else
                        {
                            isLoopingForward = false;
                        }
                    }

                    else
                    {
                        if (currentWaypoint > 0)
                        {
                            if (Vector3.SqrMagnitude(transform.position - waypoints[currentWaypoint].transform.position) <= (closeEnough * closeEnough))
                            {
                                currentWaypoint--;
                            }
                            else
                            {
                                isLoopingForward = true;
                            }
                        }
                        else
                        {
                            Debug.LogWarning("[AIController] unexpected loop type");
                        }
                        // The AI autoshoots
                        if (Time.time >= lastEventTime + timerDelay)
                        {
                            shooter.shoot();
                            lastEventTime = Time.time;
                        }
                    }
                }
            }
        }
    }