Exemple #1
0
    private bool Search(AIController controller)
    {
        float timer = controller.Remember <float>("searchInterval");

        if (timer < Time.time)
        {
            controller.Remember <float>("searchInterval", Time.time + searchInterval);

            Collider[] hitColliders = Physics.OverlapSphere(controller.aheadPoint.position, controller.profile.lookSphereCastRadius);

            if (hitColliders.Length > 0)
            {
                for (int i = 0; i < hitColliders.Length; i++)
                {
                    if ((controller.core as AIAttacker).isTarget(hitColliders[i].tag))
                    {
                        Creature.Health target = hitColliders[i].GetComponent <Creature.Health>();
                        if (target && !target.isDead)
                        {
                            controller.Remember <Creature.Health>("target", target);
                            return(true);
                        }
                    }
                }
                return(false);
            }

            controller.Remember <Creature.Health>("target", null);
        }
        return(false);
    }
Exemple #2
0
    void OnTriggerEnter(Collider col)
    {
        Creature.Health temp = col.GetComponent <Creature.Health>();
        if (temp)
        {
            temp.Damage((int)profile.damage);
        }

        Destroy();
    }
Exemple #3
0
    private void Attack(AIController controller)
    {
        float temp = controller.Remember <float>("attackTime");

        Creature.Health target = controller.Remember <Creature.Health>("target");
        if (target != null && !target.isDead && temp <= Time.time)
        {
            controller.Attack();

            controller.Remember <float>("attackTime", Time.time + controller.fireRate);
        }
    }
Exemple #4
0
    private bool Verify(AIController controller)
    {
        Creature.Health target = controller.Remember <Creature.Health>("target");

        if (target == null || target != null && target.isDead)
        {
            controller.Remember <Creature.Health>("target", null);

            return(true);
        }

        return(false);
    }
Exemple #5
0
    private void Walk(AIController controller)
    {
        Vector3 temp = controller.Remember <Vector3>("lastTargetPos");

        Creature.Health target = controller.Remember <Creature.Health>("target");

        if (target && temp != target.transform.position)
        {
            controller.agent.destination = target.transform.position;
            controller.Remember <Vector3>("lastTargetPos", target.transform.position);

            controller.agent.isStopped = false;
        }
    }
Exemple #6
0
    private void LookAt(AIController controller)
    {
        Vector3 temp = controller.Remember <Vector3>("lastTargetPos");

        Creature.Health target = controller.Remember <Creature.Health>("target");

        if (target)
        {
            float distance = Mathf.Abs(Vector3.Distance(controller.transform.position, target.transform.position));
            if (distance > controller.profile.lookRange)
            {
                temp = Vector3.Lerp(target.transform.position, controller.transform.position, controller.profile.lookRange * 100 / distance);
                controller.Remember <Vector3>("lastTargetPos", temp);
                controller.agent.isStopped = false;
            }
            else if (!controller.agent.isStopped)
            {
                controller.agent.isStopped = true;
            }


            controller.LookAt(target.transform.position);
        }
    }