Пример #1
0
    public static Steering GetSteering(Agent target, Agent npc, float maxDist, float distanceBoundary, float maxAccel, float evadePrediction, float faceTimeToTarget)
    {
        float   minDist        = maxDist;
        Vector3 bestHidingSpot = Vector3.zero;
        bool    changed        = false;

        LayerMask obstacleMask = LayerMask.GetMask("Wall");

        Collider[] hits = Physics.OverlapSphere(npc.position, minDist + distanceBoundary + 0.5f, obstacleMask);
        foreach (Collider coll in hits)
        {
            Vector3 hidingSpot = Hide.GetHidingPosition(coll.GetComponent <Body>(), npc.interiorRadius, target.position, distanceBoundary);
            float   distance   = Vector3.Distance(hidingSpot, npc.position);
            if (distance < minDist)
            {
                minDist        = distance;
                bestHidingSpot = hidingSpot;
                changed        = true;
            }
        }

        if (changed == false)
        {
            return(Evade.GetSteering(target, npc, maxAccel, evadePrediction, true));
        }
        else
        {
            return(Arrive.GetSteering(bestHidingSpot, npc, npc.exteriorRadius, maxAccel));
        }
    }