Beispiel #1
0
    void Patrol()
    {
        if (waypoints.Length > 0)
        {
            npcMove.MoveTo(waypoints[nextWaypoint].position);
            if (npcMove.HaveReachedDestination())
            {
                nextWaypoint = Random.Range(0, waypoints.Length);
            }
        }

        else        //  Wander about if there are no waypoints
        {
            if (npcMove.HaveReachedDestination())
            {
                npc.StopWalking();
                if (RandomWanderTarget(npc.transform.position, npc.sightRange, out npc.wanderLocation))
                {
                    npcMove.MoveTo(npc.wanderLocation);
                }
            }
        }
    }
Beispiel #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();
            }
        }
    }
Beispiel #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();
        }
    }