Ejemplo n.º 1
0
    private void MoveAway()
    {
        float minDist = float.MaxValue;
        float tmp;

        xDest = Random.Range(-10.7f, 9.7f);
        zDest = Random.Range(-6.7f, 6.7f);

        foreach (GameObject ag in AllAgents.agents)
        {
            tmp = AgentEvacuation.CalculateDistanceSquare(ag.transform.position, new Vector3(xDest, 0.0f, zDest));

            if (tmp < minDist)
            {
                minDist = tmp;
            }
        }

        //distance must be greater than 1.5f
        if (minDist >= 2.25f)
        {
            isSeekingForDistance = false;
            obstacle.enabled     = false;
            agent.enabled        = true;
            agent.SetDestination(new Vector3(xDest, this.gameObject.transform.position.y, zDest));
            currentState = States.GOINGAWAY;
            animator.SetBool("isWaiting", false);
            animator.SetBool("isEating", false);
            animator.SetBool("isTalking", false);
            animator.Rebind();
            animator.SetBool("isWalking", true);
        }
    }
Ejemplo n.º 2
0
    private void CheckReachPerson()
    {
        if (agent.enabled)
        {
            if (!agent.pathPending)
            {
                if (AgentEvacuation.CalculateDistanceSquare(gameObject.transform.position, personToTalk.transform.position) <= 1.0f)
                {
                    animator.SetBool("isWalking", false);
                    animator.Rebind();
                    animator.SetBool("isTalking", true);
                    agent.enabled    = false;
                    obstacle.enabled = true;
                    currentState     = States.TALKING;
                    Vector3    relativePos = personToTalk.transform.position - this.gameObject.transform.position;
                    Quaternion rotation    = Quaternion.LookRotation(relativePos, Vector3.up);
                    this.gameObject.transform.rotation = rotation;

                    // if this agent is the first to reach the person who wants to talk, it triggers the state and animation
                    if (personToTalk.GetComponent <AgentManager>().currentState != States.TALKING)
                    {
                        Vector3    rPos = this.gameObject.transform.position - personToTalk.transform.position;
                        Quaternion rot  = Quaternion.LookRotation(rPos, Vector3.up);
                        personToTalk.transform.rotation = rot;
                        personToTalk.GetComponent <AgentManager>().animator.SetBool("isWaiting", false);
                        personToTalk.GetComponent <AgentManager>().animator.Rebind();
                        personToTalk.GetComponent <AgentManager>().animator.SetBool("isTalking", true);
                        personToTalk.GetComponent <AgentManager>().currentState = States.TALKING;
                        foreach (GameObject ag in personToTalk.GetComponent <AgentManager>().talkers)
                        {
                            ag.GetComponent <AgentManager>().talkers.Add(personToTalk);
                            foreach (GameObject ag2 in personToTalk.GetComponent <AgentManager>().talkers)
                            {
                                if (ag != ag2)
                                {
                                    ag.GetComponent <AgentManager>().talkers.Add(ag2);
                                }
                            }
                        }
                    }
                }
            }
        }

        if ((personToTalk.GetComponent <AgentManager>().currentState != States.TALKING) && (personToTalk.GetComponent <AgentManager>().currentState != States.WANTTOTALK))
        {
            foreach (GameObject ag in talkers)
            {
                ag.GetComponent <AgentManager>().talkers.Remove(this.gameObject);
            }
            talkers.Clear();
            animator.SetBool("isWalking", false);
            animator.Rebind();
            animator.SetBool("isWaiting", true);
            agent.enabled    = false;
            obstacle.enabled = true;
            currentState     = States.WAITING;
        }
    }
Ejemplo n.º 3
0
    // Choose the closest table
    private int ClosestTableIndex()
    {
        int   Index       = 0;
        float MinDistance = float.MaxValue;
        float tmp;

        for (int i = 0; i < TableNbr; i++)
        {
            tmp = AgentEvacuation.CalculateDistanceSquare(gameObject.transform.position, new Vector3(Tables[i].x, 0.0f, Tables[i].y));

            if (MinDistance > tmp)
            {
                MinDistance = tmp;
                Index       = i;
            }
        }

        return(Index);
    }