Esempio n. 1
0
        /// <summary>
        /// Check if the ai has reached the current patrol point, if so send an event.
        /// </summary>
        /// <param name="_controller">Patrolling ai.</param>
        /// <returns></returns>
        private bool HasReachedPatrolPoint(AIView _controller)
        {
            Actor      _actor = _controller.GetOwner;
            PatrolData _data  = _controller.GetStateData <PatrolData>();

            bool reachedPatrolPoint = false;

            Vector3 currentPosition = _actor.transform.position;
            Vector3 patrolPosition  = _data.GetPatrolPosition;

            // So the vector is flat and in the same plane as the character.
            patrolPosition.y = currentPosition.y;
            float sqrdistance = (patrolPosition - currentPosition).sqrMagnitude;

            if (currentPosition.Equals(patrolPosition) || sqrdistance <= 0.1f)
            {
                reachedPatrolPoint = true;

                OnPatrolPointReachedEventArgs args = new OnPatrolPointReachedEventArgs()
                {
                    actor = _actor
                };

                EventController.QueueEvent(DecisionEvents.PATROL_POINT_REACHED, args);
            }

            return(reachedPatrolPoint);
        }
Esempio n. 2
0
        // TODO patrol and chase are very similar.
        private void PatrolAction(AIView _controller)
        {
            if (_controller.GetAIData.GetNavigationComponent.isStopped)
            {
                _controller.GetAIData.GetNavigationComponent.isStopped = false;
            }

            PatrolData data           = _controller.GetStateData <PatrolData>();
            Vector3    targetPosition = data.GetPatrolPosition;

            OnActorCommandReceiveEventArgs args = new OnActorCommandReceiveEventArgs()
            {
                baseArgs = new OnActorEventEventArgs()
                {
                    actor = _controller.GetOwner
                },
                command = ActorCommands.Move,
                value   = targetPosition
            };

            EventController.QueueEvent(ActorEvents.ACTOR_COMMAND_RECEIVE, args);
        }