public void SetLastWayPoint()
 {
     if (Target)
     {
         LastWayPoint = Target.GetComponentInParent <IWayPoint>() ?? LastWayPoint; //If not is a waypoint save the last one
     }
 }
        /// <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
        }
Beispiel #3
0
    public void MoveToDestination(IWayPoint start_waypoint, IWayPoint target_waypoint, float speed)
    {
        StopAllCoroutines();
        List <IWayPoint> waypoints = TileManager.Instance.FindPath((Tile)start_waypoint, (Tile)target_waypoint, null).Cast <IWayPoint>().ToList();

        StartCoroutine(PatrolWaypoints(CreateWaypoints(waypoints, speed)));
    }
Beispiel #4
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;
        }
Beispiel #5
0
        public void SetLastWayPoint(Transform target)
        {
            var newLastWay = target.gameObject.FindInterface <IWayPoint>();

            if (newLastWay != null)
            {
                LastWayPoint = target?.gameObject.FindInterface <IWayPoint>();                      //If not is a waypoint save the last one
            }
        }
        void Start()
        {
            Animal.isPlayer.Value = false; //If is using a brain... disable that he is the main player
            StartNewState(currentState);

            AIMovement.AutoNextTarget = false;

            LastWayPoint = null;

            if (AIMovement.Target)
            {
                SetLastWayPoint(AIMovement.Target);
            }
        }
Beispiel #7
0
        /// <summary>Set the next Destination Position without having a target</summary>
        public virtual void SetDestination(Vector3 PositionTarget)
        {
            IsWaiting = false;
            animal.Mode_Interrupt();             //In Case it was making any Mode;
            Stopped = false;

            StoppingDistance = DefaultStopDistance;                    //Reset the Stoppping Distance

            Debuging(name + ": is travelling to : " + PositionTarget);

            IsZone       = null;
            IsWayPoint   = null;
            NextWayPoint = null;

            if (I_WaitToNextTarget != null)
            {
                StopCoroutine(I_WaitToNextTarget);                     //if there's a coroutine active then stop it
            }
            TargetPosition = PositionTarget;                           //Update the Target Position
            ResumeAgent();
        }
Beispiel #8
0
        /// <summary>Set the next Target</summary>
        public virtual void SetTarget(Transform target)
        {
            IsWaiting = false;
            animal.Mode_Interrupt();             //In Case it was making any Mode;
            Stopped     = false;
            this.target = target;

            // Debug.Log("targetPosition: " + targetPosition.ToString("F2"));

            if (target == null)
            {
                Stop();
            }
            else
            {
                TargetPosition = target.position;                           //Update the Target Position

                IsZone = target.GetComponent <Zone>();

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



                StoppingDistance = DefaultStopDistance;                     //Reset the Stoppping Distance

                if (NextWayPoint != null)
                {
                    StoppingDistance = NextWayPoint.StoppingDistance;
                    NextTarget       = NextWayPoint.NextTarget;
                }
                // StoppingDistance = NextWayPoint != null ? NextWayPoint.StoppingDistance : DefaultStopDistance;  //Set the Next Stopping Distance

                CheckAirTarget();

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

                ResumeAgent();
            }
        }
Beispiel #9
0
        void Start()
        {
            Animal.isPlayer.Value = false; //If is using a brain... disable that he is the main player

            if (currentState)
            {
                Debuging($"<color=white> Setting First AI State <B>[{currentState.name}]</B> </color>");
                StartNewState(currentState);
            }
            else
            {
                enabled = false;
                return;
            }
            AIMovement.AutoNextTarget = false;

            LastWayPoint = null;

            if (AIMovement.Target)
            {
                SetLastWayPoint(AIMovement.Target);
            }
        }
Beispiel #10
0
 void LogPos(IWayPoint wp)
 {
     MDebug.Log(wp.GetPosition().ToString());
 }
Beispiel #11
0
 void Ended(IWayPoint point)
 {
     target.OnMovementEnd     -= Ended;
     target.OnMoveToWayPoint  -= LogPos;
     target.OnWayPointreached -= LogPos;
 }
Beispiel #12
0
 public WaypointInfo(IWayPoint p, float t, AnimationCurve c)
 {
     Waypoint       = p;
     TimeToWaypoint = t;
     MovementCurve  = c;
 }
Beispiel #13
0
 public void SetLastWayPoint(Transform target)
 {
     LastWayPoint = target.GetComponentInParent <IWayPoint>() ?? LastWayPoint; //If not is a waypoint save the last one
 }
Beispiel #14
0
 IEnumerator TurnToWaypoint(IWayPoint wp)
 {
     //  MDebug.Log("Turn to");
     yield return(new WaitForRotation(m_rotated.transform, M_Math.RotateToYFlat(m_rotated.transform.position, wp.GetPosition()), 0.35f));
     //  MDebug.Log("Rotated");
 }
Beispiel #15
0
 void OnMoveEnd(IWayPoint wp)
 {
     OnDestinationReached.AttemptCall(wp as Tile);
     Owner.GetComponent <WaypointMover>().OnMovementEnd -= OnMoveEnd;
     StartCoroutine(DelayedCompletion(0.5f));
 }
Beispiel #16
0
 public void Deconstruct(out GameObject enemy, out IWayPoint wayPoint)
 {
     enemy    = EnemyToSpawn;
     wayPoint = StartWayPoint;
 }
Beispiel #17
0
 public WaveSpawnData(GameObject enemy, IWayPoint waypoint)
 {
     EnemyToSpawn  = enemy;
     StartWayPoint = waypoint;
 }