Example #1
0
    public override void Update(AIShipController controller)
    {
        if (attackObject == null)
        {
            controller.SetBehaviour(new IdleState());
        }

        substateTimer -= Time.deltaTime;
        switch (currentSubstate)
        {
            case substates.moveTowards:
                MoveTowards();
                break;

            case substates.flee:
                Flee();
                break;

            case substates.flank:
                Flank();
                break;
        }

        controller.MoveTowards(moveToPosition);
        if (DistanceToTarget() < controller.engageRange)
        {
            FireAtTarget();
        }
    }
Example #2
0
 public override void Update(AIShipController controller)
 {
     if (controller.Ship.rigidbody.velocity.magnitude > 0 || controller.Ship.rigidbody.velocity.magnitude < 0)
     {
         controller.Stop();
     }
 }
Example #3
0
 public override void Update(AIShipController controller)
 {
     if (attackObject == null)
     {
         controller.SetBehaviour(new IdleState());
     }
     controller.Ship.TurretController.SetTarget(attackObject);
     TurnToBearWeapons();
 }
Example #4
0
 public override void Update(AIShipController controller)
 {
     if (Vector3.Distance(controller.Ship.transform.position, _defendPosition) > 10f)
     {
         controller.Arrive(_defendPosition);
     }
     else
     {
         controller.SetHeading(_originalShipDirection);
     }
 }
Example #5
0
    public override void Update(AIShipController controller)
    {
        wanderTarget += new Vector3(Random.Range(-wanderJitter, wanderJitter),
                                   Random.Range(-wanderJitter, wanderJitter),
                                   Random.Range(-wanderJitter, wanderJitter));

        wanderTarget.Normalize();
        wanderTarget *= wanderRadius;
        Vector3 point = controller.Ship.transform.position + (controller.Ship.transform.forward + (wanderTarget * wanderDistance));
        controller.MoveTowards(point);
    }
Example #6
0
 public override void Start(AIShipController controller)
 {
     if (controller.engageType == AIShipController.EngageTypes.pursue)
     {
         controller.SetBehaviour(new AttackStatePursue(attackObject));
     }
     else if (controller.engageType == AIShipController.EngageTypes.broadside)
     {
         controller.SetBehaviour(new AttackStateBroadside(attackObject));
     }
 }
Example #7
0
    public override void Update(AIShipController controller)
    {
        evadeTimer += Time.deltaTime;
        if (evadeTimer >= evadeDelay)
        {
            controller.SetBehaviour(new IdleState());
        }
        controller.SetSpeed(controller.Ship.maxSpeed);

        Vector3 directionToFlee = evadeShip.transform.position - controller.Ship.transform.position;
        directionToFlee.Normalize();

        controller.SetHeading(directionToFlee);
    }
Example #8
0
    public override void Update(AIShipController controller)
    {
        float distanceToDestination = Vector3.Magnitude(controller.Ship.transform.position - destination);

        Ray ray = new Ray(controller.Ship.transform.position, destination);
        if (!Physics.Raycast(ray, distanceToDestination)) //direct path to destination
        {
            controller.SetBehaviour(new MoveState(destination));
        }
        else
        {
            Vector3 fromPointToShip = avoidObject.transform.position - controller.Ship.transform.position;
            fromPointToShip.Normalize();
            Vector3 radiusPoint = fromPointToShip * avoidRadius;
            controller.SetHeading(controller.Ship.transform.position - radiusPoint);
        }
    }
Example #9
0
    public override void Update(AIShipController controller)
    {
        if (movementLocationIndicator == null)
        {
            movementLocationIndicator = (GameObject)GameObject.Instantiate(controller.movementLocationIndicatorPrefab, moveToPosition, Quaternion.identity);
        }

        if (!hasArrived)
        {
            controller.Arrive(moveToPosition);
            if (Vector3.Distance(controller.Ship.transform.position, moveToPosition) < 1)
            {
                hasArrived = true;
            }
        }
        else
        {
            controller.Stop();
        }
    }
Example #10
0
 public override void Start(AIShipController controller)
 {
     base.Start(controller);
 }
Example #11
0
 public override void Update(AIShipController controller)
 {
     controller.MoveTowards(controller.Ship.transform.position + (controller.Ship.transform.forward * 100));
 }
Example #12
0
 public abstract void Update(AIShipController controller);
Example #13
0
 public override void Start(AIShipController controller)
 {
     this.controller = controller;
     controller.engageRange = 1000;
 }
Example #14
0
    public override void Update(AIShipController controller)
    {
        //call to set turret target
        SetTarget(attackObject);

        if (!attackObject.activeInHierarchy)
        {
            attackObject = null;
        }

        if (attackObject != null)
        {
            Debug.DrawLine(controller.Ship.transform.position, attackObject.transform.position);

            Vector3 direction = (attackObject.transform.position - controller.Ship.transform.position).normalized;
            float distance = Vector3.Distance(controller.Ship.transform.position, attackObject.transform.position);

            if (controller.engageType == AIShipController.EngageTypes.launch)
            {
                direction = (attackObject.transform.position - (controller.Ship.transform.position * controller.engageRange)).normalized;
            }

            if (distance < controller.engageRange)
            {
                if (controller.engageType == AIShipController.EngageTypes.pursue ||
                    controller.engageType == AIShipController.EngageTypes.launch)
                {
                    if (distance < 100)
                    {
                        controller.Flee(attackObject.transform.position);
                    }
                    else if (Vector3.Dot(controller.Ship.transform.forward, direction) < 0f)
                    {
                        //loop back on target after a certain distance away
                        controller.SetSpeed(controller.Ship.maxSpeed);
                        controller.SetHeading(controller.Ship.transform.forward); //keep flying straight
                    }
                }
                else if (controller.engageType == AIShipController.EngageTypes.stand)
                {
                    controller.SetSpeed(0);
                    controller.SetHeading(attackObject.transform.position - controller.Ship.transform.position);
                }
                else if (controller.engageType == AIShipController.EngageTypes.broadside)
                {
                    controller.SetSpeed(0);

                    if (Vector3.Dot(controller.Ship.transform.right, direction) < Vector3.Dot(-controller.Ship.transform.right, direction))
                    {
                        //turn left
                        controller.SetHeading(Vector3.Cross(controller.Ship.transform.up, direction));
                    }
                    else
                    {
                        //turn right
                        controller.SetHeading(Vector3.Cross(-controller.Ship.transform.up, direction));
                    }
                }
            }
            else
            {
                Vector3 position = attackObject.transform.position;

                if (controller.Ship.Weapons.Count > 0)
                {
                    position = controller.Ship.Weapons[0].GetLeadPosition(attackObject);
                }

                if (distance > controller.engageRange)
                {
                    position -= direction * controller.engageRange;

                    controller.MoveTowards(position);
                }
            }

            if (distance < controller.engageRange)
            {
                foreach (Weapon weapon in controller.Ship.Weapons)
                {
                    Ray ray = new Ray(weapon.transform.position, weapon.transform.forward);

                    if (weapon.CanFire() && weapon.ChanceToHit(attackObject) > 0.98f)
                    {
                        bool lineToTarget = true;

                        RaycastHit hit;
                        if (Physics.Raycast(ray, out hit, Vector3.Distance(controller.Ship.transform.position, attackObject.transform.position)))
                        {
                            if (hit.collider.tag != "Ship")
                            {
                                lineToTarget = false;
                            }
                            else
                            {
                                Ship ship = hit.collider.gameObject.GetComponent<Ship>();

                                if (ship.FactionID == controller.Ship.FactionID)
                                {
                                    //friendly ship in the way
                                    lineToTarget = false;
                                }
                            }
                        }

                        if (lineToTarget)
                        {
                            if (weapon is MissileLauncher)
                            {
                                MissileLauncher missileLauncher = (MissileLauncher)weapon;
                                missileLauncher.SetTarget(attackObject);
                            }

                            float accuracy = controller.accuracy;
                            Vector3 leadPosition = weapon.GetLeadPosition(attackObject);
                            Vector3 leadDirection = (leadPosition - weapon.transform.position).normalized;
                            Vector3 fireDirection = new Vector3(leadDirection.x + Random.Range(-accuracy, accuracy),
                                                                leadDirection.y + Random.Range(-accuracy, accuracy),
                                                                leadDirection.z);
                            fireDirection.Normalize();
                            Ray fireRay = new Ray(controller.Ship.transform.position, fireDirection);
                            weapon.FireAtAngle(fireRay);

                            AIShipController targetShipController = attackObject.GetComponent<AIShipController>();
                            if (targetShipController != null)
                            {
                                targetShipController.OnAttacked(controller.Ship);
                            }
                        }
                    }
                }
            }

            controller.Target = attackObject;
        }
        else
        {
             //allows the squadron state to set a new target
            controller.SetBehaviour(new IdleState());
        }
    }
Example #15
0
    public override void Update(AIShipController controller)
    {
        Vector3 position = followObject.transform.localPosition;

        controller.MoveTowards(position);
    }
Example #16
0
 public override void Start(AIShipController controller)
 {
     this.controller = controller;
     controller.engageRange = 1000;
     UpdateWeaponTargets();
 }
Example #17
0
 public override void Start(AIShipController controller)
 {
 }
    // Use this for initialization
    IEnumerator Start()
    {
        aiShip = transform.GetComponentInChildren<AIShipController>();
        //Debug.Log (aiShip.ToString());
        dm = transform.GetComponentInChildren<DamageManager>();
        //Debug.Log (dm.ToString());
        playerShip = GameObject.FindWithTag("Player");
        //Debug.Log (playerShip.GetFullName());
        demoTree = BLAIDemo.InstantiateTree(
            BLAIDemo.TreeType.AIDemo_DemoTree, this);

        while(Application.isPlaying && demoTree != null)
        {
            Debug.Log (this.transform.name + " updating AI state");
            yield return new WaitForSeconds(1.0f / demoTree.Frequency);
            AIUpdate();
        }
    }
Example #19
0
 public virtual void Start(AIShipController controller)
 {
     this.controller = controller;
 }