コード例 #1
0
    //  Set Location Of Interest.
    void ScanForTargets()
    {
        npc.UpdateStateIndicator(stateIndicatorColor);

        colliders = Physics.OverlapSphere(npc.transform.position, npc.sightRange, npc.myEnemyLayers);

        foreach (Collider col in colliders)
        {
            RaycastHit hit;
            Transform  target = col.transform;

            npcSight.VisibilityCalculations(target);

            if (npcSight.angleBetweenNpcAndPlayer < npc.viewAngle / 2f)
            {
                if (Physics.Linecast(npcSight.headPosition, npcSight.targetPosition, out hit, npc.mySightLayers))
                {
                    foreach (string tags in npc.myEnemyTags)
                    {
                        if (hit.transform.CompareTag(tags))
                        {
                            Debug.DrawLine(npcSight.headPosition, npcSight.targetPosition, Color.red);
                            AlertStateActions(target);
                            return;
                        }
                    }
                }
            }
        }
    }
コード例 #2
0
    void GoToLocationOfInterest(Vector3 locationOfInterest)
    {
        npc.UpdateStateIndicator(stateIndicatorColor);

        if (npc.myNavMeshAgent.enabled && locationOfInterest != Vector3.zero)
        {
            //Vector3 randomPosition = npc.RandomPositionAroundTarget(locationOfInterest);
            npcMove.MoveTo(locationOfInterest);

            if (npc.myNavMeshAgent.remainingDistance <= npc.myNavMeshAgent.stoppingDistance && npc.myNavMeshAgent.pathPending == false)
            {
                // npc.npcMaster.CallEventNpcIdleAnim();
                npc.SetLocationOfInterest(Vector3.zero, false);
                ToPatrolState();
            }
        }
    }
コード例 #3
0
    void Pursue()
    {
        npc.UpdateStateIndicator(stateIndicatorColor);


        if (npc.myNavMeshAgent.enabled && npc.pursueTarget != null)
        {
            npcMove.MoveTo(npc.pursueTarget.position);
            npc.locationOfInterest = npc.pursueTarget.position;              // used by if npc goes to alert state.

            float distanceToTarget = Vector3.Distance(npc.transform.position, npc.pursueTarget.position);
            //  Check npc can see target and is in range.
            if (distanceToTarget <= npc.sightRange && npcSight.CanSeeTarget(npc, npc.pursueTarget))
            {
                ToRangeAttackState();
                npc.StopWalking();
            }
        }
        else
        {
            ToAlertState();
        }
    }