예제 #1
0
    private void ChooseWaitPos()
    {
        // look how many people are waiting on this side
        int nbWalkers = (waitType == WaitType.Crosswalk ?
                         crossWalk.GetComponentInChildren <CheckWalkers>().GetWalkersWaiting(CheckWhichSide()).Count
                        : trafficLightRef.GetComponentInParent <CheckWalkers>().GetWalkersWaiting(CheckWhichSide()).Count) - 1; // - 1 because it counts itself

        // get the reference point
        Transform closest;

        CheckWhichSide(out closest);

        if (nbWalkers == 0)
        {
            agent.SetDestination(closest.position);             // if this is the first walker to arrive, he goes on the waiting point
        }
        else
        {
            // else we use the angles that were precalculated to determine the waiting pos (this sould form half-circles around the first waiting walker)
            for (int i = 0; i < angles.Length; i++)
            {
                int nbMaxWalkers = (int)(Mathf.PI / angles[i]);
                if (nbWalkers >= nbMaxWalkers)
                {
                    nbWalkers -= nbMaxWalkers;
                }
                else
                {
                    agent.SetDestination(closest.position + closest.right * Mathf.Cos(-angles[i] * nbWalkers) * 1.5f + closest.forward * Mathf.Sin(-angles[i] * nbWalkers) * 1.5f);
                }
            }
        }
    }