Exemple #1
0
    void OnTriggerStay(Collider other)
    {
        if (other.CompareTag("Player") || other.CompareTag("PlayerParts"))
        {
            Vector3 direction = other.transform.position - transform.position;

            if (Physics.Raycast(transform.position, direction.normalized, out hit))
            {
                if (hit.collider.gameObject == player)
                {
                    if (hit.distance > 60)
                    {
                        ai.Chase();
                    }
                    if (hit.distance <= 40)
                    {
                        ai.Attack();
                    }
                }
            }
            else
            {
                ai.Idle();
            }
        }
    }
Exemple #2
0
    public override NodeState Evaluate()
    {
        float distance = Vector3.Distance(player.position, agent.transform.position);

        if (distance > 0.2f)
        {
            agent.isStopped = false;
            agent.SetDestination(player.position);
            ai.Chase(true);
            return(NodeState.Running);
        }
        else
        {
            ai.Chase(false);
            agent.isStopped = true;
            return(NodeState.Success);
        }
    }
Exemple #3
0
    public override NodeState Evaluate()
    {
        ai.Chase(Color.yellow);
        float distance = Vector3.Distance(target.position, agent.transform.position);

        //为了防止距离玩家太近
        if (distance > 0.2f)
        {
            agent.isStopped = false;
            agent.SetDestination(target.position);
            return(NodeState.RUNNING);
        }
        else
        {
            agent.isStopped = true;
            return(NodeState.SUCCESS);
        }
    }