/** \copydoc Pathfinding::IAstarAI::Teleport */ public override void Teleport(Vector3 newPosition, bool clearPath = true) { if (clearPath) { interpolator.SetPath(null); } reachedEndOfPath = false; base.Teleport(newPosition, clearPath); }
protected override void OnDisable() { base.OnDisable(); // Release current path so that it can be pooled if (path != null) { path.Release(this); } path = null; interpolator.SetPath(null); }
private void OnPathComplete(Path path) { path.Claim(this); _isSearchingPath = false; _isAtDestination = false; if (path.error) { path.Release(this); return; } if (_path != null) { _path.Release(this); } _path = path as ABPath; var graph = AstarData.GetGraph(path.path[0]) as ITransformedGraph; _movementPlane = graph != null ? graph.transform : GraphTransform.identityTransform; if (_path.vectorPath.Count == 1) { _path.vectorPath.Add(_path.vectorPath[0]); } _interpolator.SetPath(_path.vectorPath); var position = transform.position; _interpolator.MoveToLocallyClosestPoint((position + _path.originalStartPoint) * 0.5f); _interpolator.MoveToLocallyClosestPoint(position); }
public void OnDisable() { if (seeker != null) { seeker.CancelCurrentPathRequest(); } canSearchAgain = true; if (path != null) { path.Release(this); } path = null; interpolator.SetPath(null); seeker.pathCallback -= OnPathComplete; }
/// <summary> /// Clears the current path of the agent. /// /// Usually invoked using <see cref="SetPath(null)"/> /// /// See: <see cref="SetPath"/> /// See: <see cref="isStopped"/> /// </summary> protected virtual void ClearPath() { // Abort any calculations in progress if (seeker != null) { seeker.CancelCurrentPathRequest(); } canSearchAgain = true; reachedEndOfPath = false; // Release current path so that it can be pooled if (path != null) { path.Release(this); } path = null; interpolator.SetPath(null); }
/** Called when a requested path has finished calculation. * A path is first requested by #SearchPath, it is then calculated, probably in the same or the next frame. * Finally it is returned to the seeker which forwards it to this function.\n */ public virtual void OnPathComplete(Path _p) { ABPath p = _p as ABPath; if (p == null) { throw new System.Exception("This function only handles ABPaths, do not use special path types"); } canSearchAgain = true; // Claim the new path p.Claim(this); // Path couldn't be calculated of some reason. // More info in p.errorLog (debug string) if (p.error) { p.Release(this); return; } // Release the previous path if (path != null) { path.Release(this); } // Replace the old path path = p; // Make sure the path contains at least 2 points if (path.vectorPath.Count == 1) { path.vectorPath.Add(path.vectorPath[0]); } interpolator.SetPath(path.vectorPath); // REPLACEMENT // var graph = AstarData.GetGraph(path.path[0]) as ITransformedGraph; // movementPlane = graph != null ? graph.transform : GraphTransform.identityTransform; var graphRotation = new Vector3(-90, 0, 0); movementPlane = new GraphTransform(Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(graphRotation), Vector3.one)); // Reset some variables TargetReached = false; // Simulate movement from the point where the path was requested // to where we are right now. This reduces the risk that the agent // gets confused because the first point in the path is far away // from the current position (possibly behind it which could cause // the agent to turn around, and that looks pretty bad). interpolator.MoveToLocallyClosestPoint((GetFeetPosition() + p.originalStartPoint) * 0.5f); interpolator.MoveToLocallyClosestPoint(GetFeetPosition()); }
public void OnDisable() { // Abort any calculations in progress if (seeker != null) { seeker.CancelCurrentPathRequest(); } canSearchAgain = true; // Release current path so that it can be pooled if (path != null) { path.Release(this); } path = null; interpolator.SetPath(null); // Make sure we no longer receive callbacks when paths complete seeker.pathCallback -= OnPathComplete; }
/** Finds the closest point on the current path and configures the #interpolator */ protected virtual void ConfigureNewPath () { var hadValidPath = interpolator.valid; var prevTangent = hadValidPath ? interpolator.tangent : Vector3.zero; interpolator.SetPath(path.vectorPath); interpolator.MoveToClosestPoint(GetFeetPosition()); if (interpolatePathSwitches && switchPathInterpolationSpeed > 0.01f && hadValidPath) { var correctionFactor = Mathf.Max(-Vector3.Dot(prevTangent.normalized, interpolator.tangent.normalized), 0); interpolator.distance -= speed*correctionFactor*(1f/switchPathInterpolationSpeed); } }
public void SetPath(List <Vector3> path) { interpolator.SetPath(path); }