public PatrolWaypointFactory(PatrolWaypoint prefab, AI.AStar.Grid grid)
        {
            if (!(prefab && grid))
            {
                throw new System.ArgumentNullException();
            }

            this.prefab = prefab;
            this.grid   = grid;
        }
Esempio n. 2
0
        protected virtual void SetPatrolling()
        {
            Vector3        curWaypointPosition = patroller.curPatrolWaypoint.position;
            PatrolWaypoint nextWaypoint        = patroller.GetNextPatrolWaypoint();

            // Prevents animation bug where nurse briefly runs in place with only one patrol point
            if (curWaypointPosition != nextWaypoint.position)
            {
                ToggleAnimations(true);
            }

            agent.speed = patroller.movementSpeed;
            questionMark.SetActive(false);

            agent.SetDestination(nextWaypoint.position);
        }
        public PatrolWaypoint[] SpawnWaypoints(int count = 3)
        {
            Vector3 center = grid.WorldBottomLeft + new Vector3(grid.WorldSize.x / 2, 0, grid.WorldSize.y / 2);

            var waypoints = new PatrolWaypoint[count];

            float degrees = 0;

            for (int i = 1; i < count; ++i)
            {
                var     rotation  = Quaternion.Euler(0, degrees, 0);
                Vector3 direction = rotation * Vector3.forward;
                Vector3 position  = center + direction * grid.WorldSize.x * 0.4f;

                degrees += 360f / (count - 1);

                waypoints[i] = MonoBehaviour.Instantiate(prefab, position, prefab.transform.rotation);
            }

            waypoints[0] = MonoBehaviour.Instantiate(prefab, center, prefab.transform.rotation);

            return(waypoints);
        }
Esempio n. 4
0
        void Update()
        {
            if (IsPaused)
            {
                return;
            }

            if (_navMeshAgent.remainingDistance <= WaypointOffset && !_hasReachedDestination)
            {
                _hasReachedDestination = true;

                PatrolWaypoint patrolWaypoint = _path[_currentWaypoint].GetComponent <PatrolWaypoint>();
                if (patrolWaypoint != null)
                {
                    _stopTime = Random.Range(patrolWaypoint.StopDuration - patrolWaypoint.StopDurationVariation, patrolWaypoint.StopDuration + patrolWaypoint.StopDurationVariation);
                    if (Random.value >= patrolWaypoint.StopProbability)
                    {
                        GoToNextWaypoint();
                    }
                }
                else
                {
                    GoToNextWaypoint();
                }
            }

            if (_hasReachedDestination)
            {
                _stopTime -= Time.deltaTime;

                if (_stopTime <= 0)
                {
                    GoToNextWaypoint();
                }
            }
        }