Exemplo n.º 1
0
 //Mise à jour du chemin
 void UpdatePath()
 {
     if (seeker.IsDone())
     {
         seeker.StartPath(rb.position, target.position, OnPathComplete);
     }
 }
Exemplo n.º 2
0
 // Start is called before the first frame update
 void Start()
 {
     waitTime      = startWaitTime;
     nextSpot      = 0; // assuming object starts at position index 0
     isChaseActive = false;
     //detectedAnimator = GetComponentInChildren<Animator>();   // This ensures that the get call only happens once. Otherwise, it would be called every time the animation controller is updated
     foodDetected = false;
     Target       = moveSpots[1];
     mySeeker.StartPath(transform.position, Target.position);
     hasLineOfSight = false;
 }
Exemplo n.º 3
0
        /** Force recalculation of the current path.
         * If there is an ongoing path calculation, it will be canceled (so make sure you leave time for the paths to get calculated before calling this function again).
         */
        public virtual void UpdatePath()
        {
            canSearchPath      = true;
            waitingForPathCalc = false;
            Path p = seeker.GetCurrentPath();

            //Cancel any eventual pending pathfinding request
            if (p != null && !seeker.IsDone())
            {
                p.Error();
                // Make sure it is recycled. We won't receive a callback for this one since we
                // replace the path directly after this
                p.Claim(this);
                p.Release(this);
            }

            waitingForPathCalc = true;
            lastRepath         = Time.time;
            seeker.StartPath(tr.position, target.position);
        }
Exemplo n.º 4
0
        /** Requests a path to the target.
         * Bypasses 'is-it-a-good-time-to-request-a-path' checks.
         */
        public virtual void ForceSearchPath()
        {
            if (float.IsPositiveInfinity(destination.x))
            {
                return;
            }
            if (onSearchPath != null)
            {
                onSearchPath();
            }

            lastRepath = Time.time;

            // This is where the path should start to search from
            var currentPosition = GetFeetPosition();

            // If we are following a path, start searching from the node we will
            // reach next this can prevent odd turns right at the start of the path

            /*if (interpolator.valid) {
             *  var prevDist = interpolator.distance;
             *  // Move to the end of the current segment
             *  interpolator.MoveToSegment(interpolator.segmentIndex, 1);
             *  currentPosition = interpolator.position;
             *  // Move back to the original position
             *  interpolator.distance = prevDist;
             * }*/

            canSearchAgain = false;

            // Alternative way of creating a path request
            //ABPath p = ABPath.Construct(currentPosition, targetPoint, null);
            //seeker.StartPath(p);

            // Create a new path request
            // The OnPathComplete method will later be called with the result
            seeker.StartPath(currentPosition, destination);
        }
Exemplo n.º 5
0
        /// <summary>\copydoc Pathfinding::IAstarAI::SetPath</summary>
        public void SetPath(Path path)
        {
            if (path == null)
            {
                CancelCurrentPathRequest();
                ClearPath();
            }
            else if (path.PipelineState == PathState.Created)
            {
                // Path has not started calculation yet
                waitingForPathCalculation = true;
                seeker.CancelCurrentPathRequest();
                seeker.StartPath(path);
                autoRepath.DidRecalculatePath(destination);
            }
            else if (path.PipelineState >= PathState.Returning)
            {
                // Path has already been calculated

                // We might be calculating another path at the same time, and we don't want that path to override this one. So cancel it.
                if (seeker.GetCurrentPath() != path)
                {
                    seeker.CancelCurrentPathRequest();
                }
                else
                {
                    throw new System.ArgumentException("If you calculate the path using seeker.StartPath then this script will pick up the calculated path anyway as it listens for all paths the Seeker finishes calculating. You should not call SetPath in that case.");
                }

                OnPathComplete(path);
            }
            else
            {
                // Path calculation has been started, but it is not yet complete. Cannot really handle this.
                throw new System.ArgumentException("You must call the SetPath method with a path that either has been completely calculated or one whose path calculation has not been started at all. It looks like the path calculation for the path you tried to use has been started, but is not yet finished.");
            }
        }
Exemplo n.º 6
0
 public void ForceSeek(Vector3 start, Vector3 end)
 {
     seeker.StartPath(start, end, Callback);
 }