Exemple #1
0
 void OnTriggerEnter(Collider col)
 {
     if (col.tag == "WP")
     {
         targetWaypoint = wp.GetNextWaypoint(targetWaypoint);
     }
     if (col.tag == "Projectile")
     {
         Projectile p = col.GetComponent <Projectile>();
         TakeHit(p.damage, p.origin);
         col.gameObject.GetComponent <Renderer>().enabled       = false;
         col.gameObject.GetComponent <SphereCollider>().enabled = false;
         col.gameObject.GetComponent <ParticleSystem>().Stop();
     }
 }
 void WaypointNavigation()
 {
     moveTarget    = waypointHolder.GetNextWaypoint();
     targetReached = false;
     MoveTowardsPosition(moveTarget, targetThreshold);
 }
Exemple #3
0
 // Use this for initialization
 void Start()
 {
     maxhealth      = health;
     wp             = GameObject.FindObjectOfType <Waypoints>();
     targetWaypoint = wp.GetNextWaypoint(targetWaypoint);
 }
                /// <summary>
                /// Prepares a waypoint target.
                /// </summary>
                /// <returns>a waypoint target as potential target candidate</returns>
                /// <description>The UpdateTarget methods only prepares and/or preselect their targets to provide a potential
                /// target candidates for the final selection.
                /// </description>
                public TargetObject PrepareTarget(GameObject _owner, CreatureObject _creature)
                {
                    if (TargetReady() == false || _owner == null || _creature == null || _creature.Behaviour == null)
                    {
                        return(null);
                    }

                    // as long as the creature is inside the max range, the duration of stay will measured, otherwise the timer will adjusted to zero.
                    if (Target.TargetInMaxRange(_owner.transform.position))
                    {
                        if (m_DurationOfStayUpdateTime > 0)
                        {
                            m_DurationOfStayTimer += Time.time - m_DurationOfStayUpdateTime;
                        }

                        m_DurationOfStayUpdateTime = Time.time;
                    }
                    else
                    {
                        m_DurationOfStayUpdateTime = 0;
                        m_DurationOfStayTimer      = 0;
                    }

                    // if the active target is not a WAYPOINT we have to find the nearest waypoint and set the travel bahaviour
                    if (_creature.ActiveTarget == null || _creature.ActiveTarget.Type != TargetType.WAYPOINT)
                    {
                        // btw. GetWaypointByPosition() changes the target, so GetBehaviourModeTravel() returns the behaviour of the new waypoint,
                        // which means, that the travel behavour always specifies the approach and not the departure.
                        Waypoints.GetWaypointByPosition(_owner.transform.position);
                        Target.BehaviourModeKey = GetBehaviourModeTravel();
                    }

                    // our creature have reached the max range of the given target waypoint - the max range is the random range plus target stop distance,
                    // or if the random range is zero just the target stop distance.
                    else if (Target.TargetMoveComplete)
                    {
                        if (GetIsTransitPoint() || GetDesiredDurationOfStay() == 0 || m_DurationOfStayTimer >= GetDesiredDurationOfStay())
                        {
                            // btw. GetNextWaypoint() changes the target, so GetBehaviourModePatrol() returns the behaviour of the new waypoint,
                            // which means, that a patrol behavour always specifies the approach and not the departure.
                            Waypoints.GetNextWaypoint();
                            Target.BehaviourModeKey = GetBehaviourModePatrol();
                        }
                        else
                        {
                            Target.BehaviourModeKey = GetBehaviourModeRendezvous();
                        }
                    }
                    else if (!GetIsTransitPoint() && Target.TargetInMaxRange(_owner.transform.position))
                    {
                        Target.BehaviourModeKey = GetBehaviourModeLeisure();
                    }
                    else
                    {
                        // before our creature can start with the patrol behaviour, it has to reach the first waypoint, so we check the
                        // previous target and if this is null or not a waypoint our creature is still travelling to the nearest waypoint
                        // which we have found in the first rule.
                        if (_creature.PreviousTarget != null && _creature.PreviousTarget.Type != TargetType.WAYPOINT)
                        {
                            Target.BehaviourModeKey = GetBehaviourModeTravel();
                        }

                        // now it looks that our creature is on the way between two waypoints and so it should use the patrol behaviour
                        else
                        {
                            Target.BehaviourModeKey = GetBehaviourModePatrol();
                        }
                    }

/*
 *                                      if( _creature.Move.CurrentTarget == Target && _creature.Move.HasDetour && _creature.Move.DetourPositionReached( _owner.transform.position ) )
 *                                      {
 *                                      }*/

                    return(Target);
                }
Exemple #5
0
 private void GetNextWaypoint()
 {
     targetWaypoint = waypoints.GetNextWaypoint(++waypointIndex);
 }
Exemple #6
0
 // Start is called before the first frame update
 void Start()
 {
     speed           = 4;
     currentWaypoint = waypoints.GetNextWaypoint();
 }