Ejemplo n.º 1
0
        /// <summary>
        /// Set to next Target
        /// </summary>
        public virtual void SetTarget(Transform target)
        {
            if (!Agent.isOnNavMesh)
            {
                return;                                   //No nothing if we are not on a Nav mesh or the Agent is disabled
            }
            if (target == null)
            {
                return;                             //If there's no target Skip the code
            }
            this.target    = target;
            targetPosition = target.position;       //Update the Target Position

            isActionZone = target.GetComponent <ActionZone>();
            isWayPoint   = target.GetComponent <MWayPoint>();
            NextWayPoint = target.GetComponent <IWayPoint>(); //Check if the Next Target has Next Waypoints

            StoppingDistance = NextWayPoint != null ? NextWayPoint.StoppingDistance :  DefaultStopDistance;

            if (debug)
            {
                Debug.Log("Target Updated: " + target.name);
            }


            Agent.SetDestination(targetPosition);                       //If there's a position to go to set it as destination
            Agent.isStopped = false;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Set the next Target
        /// </summary>
        public virtual void SetTarget(Transform target)
        {
            if (target == null)
            {
                return;                             //If there's no target Skip the code
            }
            this.target    = target;
            targetPosition = target.position;       //Update the Target Position

            isActionZone = target.GetComponent <ActionZone>();
            //TisAnimal = target.GetComponent<Animal>();                (WHAT HAPPENS IF THE TARGET IS AN ANIMAL ???? ))

            isWayPoint   = target.GetComponent <MWayPoint>();
            NextWayPoint = target.GetComponent <IWayPoint>();            //Check if the Next Target has Next Waypoints



            StoppingDistance = NextWayPoint != null ? NextWayPoint.StoppingDistance : DefaultStopDistance;  //Set the Next Stopping Distance

            CheckAirTarget();

            Debuging(name + " is travelling to : " + target.name);

            if (!Agent.isOnNavMesh)
            {
                return;                                                 //No nothing if we are not on a Nav mesh or the Agent is disabled
            }
            Agent.enabled = true;
            Agent.SetDestination(targetPosition);                       //If there's a position to go to set it as destination
            Agent.isStopped = false;                                    //Start the Agent again
        }
Ejemplo n.º 3
0
        //If the target changes do something
        void UpdateTarget()
        {
            if (deltaTarget != target)
            {
                deltaTarget = target;
                if (debug)
                {
                    Debug.Log("Target Updated: " + target.name);
                }

                Target_is_Animal     = deltaTarget ? deltaTarget.GetComponent <Animal>() : null;
                Target_is_ActionZone = deltaTarget ? deltaTarget.GetComponent <ActionZone>() : null;
                Target_is_Waypoint   = deltaTarget ? deltaTarget.GetComponent <MWayPoint>() : null;

                Agent.stoppingDistance = DefaultStoppingDistance;

                if (Target_is_ActionZone)
                {
                    Agent.stoppingDistance = Target_is_ActionZone.stoppingDistance;
                }
                else if (Target_is_Waypoint)
                {
                    Agent.stoppingDistance = Target_is_Waypoint.StoppingDistance;
                }
            }
        }
Ejemplo n.º 4
0
 public void Init(GameFactory _gameFactory, GameObject spawn, MWayPoint wayPoint, LevelContainer _levelContainer)
 {
     gameFactory    = _gameFactory;
     levelContainer = _levelContainer;
     SpawnPlayer(spawn);
     gameFactory.PlayerContainer.Init(wayPoint, Camera.main, levelContainer);
     gameFactory.PlayerContainer.PlayerShoot.IsInputInverted = SaveLoadService.Instance.GameSettings.IsInputInverted;
     gameFactory.PlayerContainer.PlayerShoot.Sensitivity     = SaveLoadService.Instance.GameSettings.Sensitivity;
 }
Ejemplo n.º 5
0
        public bool LookForClosestWaypoint(MAnimalBrain brain)
        {
            var       allWaypoints    = MWayPoint.WayPoints;
            float     minDistance     = float.MaxValue;
            MWayPoint closestWayPoint = null;

            foreach (var way in allWaypoints)
            {
                var Distance = Vector3.Distance(way.GetPosition(), brain.Eyes.position);

                if (Distance < minDistance && Distance < LookRange)
                {
                    minDistance     = Distance;
                    closestWayPoint = way;
                }
            }

            if (closestWayPoint)
            {
                return(IsInFieldOfView(brain, closestWayPoint.GetPosition(), closestWayPoint.WPTransform));  //Find if is inside the Field of view
            }
            return(false);
        }
Ejemplo n.º 6
0
 public void Init(MWayPoint wayPoint, Camera camera, LevelContainer _levelContainer)
 {
     PlayerHorseAI.SetTarget(wayPoint.transform, true);
     PlayerShoot.Init(_levelContainer, camera);
 }
Ejemplo n.º 7
0
 public void Init(Transform followTarget, Transform shootTarget, MWayPoint runAwayWaypoint)
 {
     EnemyShoot.SetTarget(shootTarget);
     EnemyPlayerFollow.SetTarget(followTarget);
     EnemyPlayerFollow.RunAwayPoint = runAwayWaypoint;
 }