public void OnDisable () { // Abort any calculations in progress if (seeker != null) seeker.CancelCurrentPathRequest(); canSearchAgain = true; // Release the current path so that it can be pooled if (path != null) path.Release(this); path = null; // Make sure we no longer receive callbacks when paths complete seeker.pathCallback -= OnPathComplete; }
/** 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 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; pointPathIndex = 0; pointDistance = Vector3.Distance(path.vectorPath [0], path.vectorPath [1]); }
/** 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; //Reset some variables currentWaypointIndex = 0; targetReached = false; //The next row can be used to find out if the path could be found or not //If it couldn't (error == true), then a message has probably been logged to the console //however it can also be got using p.errorLog //if (p.error) if (closestOnPathCheck) { Vector3 p1 = Time.time - lastFoundWaypointTime < 0.3f ? lastFoundWaypointPosition : p.originalStartPoint; Vector3 p2 = GetFeetPosition(); Vector3 dir = p2 - p1; float magn = dir.magnitude; dir /= magn; int steps = (int)(magn / pickNextWaypointDist); #if ASTARDEBUG Debug.DrawLine(p1, p2, Color.red, 1); #endif for (int i = 0; i <= steps; i++) { CalculateVelocity(p1); p1 += dir; } } }
public virtual void OnPathComplete(Path _p) { ABPath abpath = _p as ABPath; if (abpath == null) { throw new Exception("This function only handles ABPaths, do not use special path types"); } this.canSearchAgain = true; abpath.Claim(this); if (abpath.error) { abpath.Release(this, false); return; } if (this.path != null) { this.path.Release(this, false); } this.path = abpath; if (this.path.vectorPath.Count == 1) { this.path.vectorPath.Add(this.path.vectorPath[0]); } this.interpolator.SetPath(this.path.vectorPath); ITransformedGraph transformedGraph = AstarData.GetGraph(this.path.path[0]) as ITransformedGraph; this.movementPlane = ((transformedGraph == null) ? GraphTransform.identityTransform : transformedGraph.transform); this.TargetReached = false; this.interpolator.MoveToLocallyClosestPoint((this.GetFeetPosition() + abpath.originalStartPoint) * 0.5f, true, true); this.interpolator.MoveToLocallyClosestPoint(this.GetFeetPosition(), true, true); }
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"); } // Claim the new path // This is used for path pooling 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; } goalList.Add(new PathDest(p.endPoint, p.GetTotalLength())); // Release the previous path // This is used for path pooling if (path != null) { path.Release(this); } // Replace the old path path = p; }
public virtual void OnPathComplete(Path _p) { ABPath abpath = _p as ABPath; if (abpath == null) { throw new Exception("This function only handles ABPaths, do not use special path types"); } this.canSearchAgain = true; abpath.Claim(this); if (abpath.error) { abpath.Release(this, false); return; } if (this.interpolatePathSwitches) { this.ConfigurePathSwitchInterpolation(); } if (this.path != null) { this.path.Release(this, false); } this.path = abpath; this.targetReached = false; if (this.path.vectorPath != null && this.path.vectorPath.Count == 1) { this.path.vectorPath.Insert(0, this.GetFeetPosition()); } this.ConfigureNewPath(); }
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); }
// 当搜索路径完成的时候调用 private void OnPathComplete(Path _p) { ABPath p = _p as ABPath; if (p == null) { return; } //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; // 从头开始寻路 currentWaypointIndex = -1; NextWaypoint(); }
public void OnDisable() { // Abort calculation of path if (seeker != null && !seeker.IsDone()) { seeker.GetCurrentPath().Error(); } // Release current path if (path != null) { path.Release(this); } path = null; // Make sure we receive callbacks when paths complete seeker.pathCallback -= OnPathComplete; }
/// <summary> /// Called when a requested path has finished calculation. /// </summary> /// <param name="_p">_p.</param> /// <description>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. /// </description> public virtual void OnPathComplete(Path _p) { ABPath _path = _p as ABPath; if (_path == null) { throw new System.Exception("This function only handles ABPaths, do not use special path types"); } m_CanSearchAgain = true; //Claim the new path _path.Claim(this); // Path couldn't be calculated of some reason. // More info in p.errorLog (debug string) if (_path.error) { _path.Release(this); return; } //Release the previous path if (m_Path != null) { m_Path.Release(this); } //Replace the old path m_Path = _path; //Reset some variables m_CurrentWaypointIndex = 0; m_TargetReached = false; //The next row can be used to find out if the path could be found or not //If it couldn't (error == true), then a message has probably been logged to the console //however it can also be got using p.errorLog //if (p.error) if (ClosestOnPathCheck) { Vector3 _pos_1 = Time.time - m_LastFoundWaypointTime < 0.3f ? m_LastFoundWaypointPosition : _path.originalStartPoint; Vector3 _pos_2 = GetFeetPosition(); Vector3 _direction = _pos_2 - _pos_1; float _magnitude = _direction.magnitude; _direction /= _magnitude; int _steps = (int)(_magnitude / PickNextWaypointDist); for (int i = 0; i <= _steps; i++) { CalculateVelocity(_pos_1); _pos_1 += _direction; } } }
/** 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()); }
private void OnPathComplete(Path p) { if (path != null) { path.Release(this); } path = p as ABPath; path.Claim(this); }
/** 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; // Increase the reference count on the path. // This is used for path pooling 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; } if (interpolatePathSwitches) { ConfigurePathSwitchInterpolation(); } // Release the previous path // This is used for path pooling. // Note that this will invalidate the interpolator // since the vectorPath list will be pooled. if (path != null) { path.Release(this); } // Replace the old path path = p; targetReached = false; // Just for the rest of the code to work, if there // is only one waypoint in the path add another one if (path.vectorPath != null && path.vectorPath.Count == 1) { path.vectorPath.Insert(0, GetFeetPosition()); } // Reset some variables ConfigureNewPath(); }
public void OnPathComplete(Path p) { if (p.error) { Debug.Log("AI: Got Path, Detected error"); return; } if (path != null) { path.Release(gameObject); } path = p as ABPath; path.Claim(gameObject); CurrentWaypoint = 0; PathHasEnded = false; }
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; p.Claim(this); if (p.error) { p.Release(this); return; } if (path != null) { path.Release(this); } path = p; currentWaypointIndex = 0; targetReached = false; if (closestOnPathCheck) { Vector3 p1 = Time.time - lastFoundWaypointTime < 0.3f ? lastFoundWaypointPosition : p.originalStartPoint; Vector3 p2 = GetFeetPosition(); Vector3 dir = p2 - p1; float magn = dir.magnitude; dir /= magn; int steps = (int)(magn / pickNextWaypointDist); for (int i = 0; i <= steps; i++) { CalculateVelocity(p1); p1 += dir; } } }
/// <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); }
public virtual void OnPathComplete(Path _p) { ABPath path = _p as ABPath; if (path == null) { throw new Exception("This function only handles ABPaths, do not use special path types"); } this.canSearchAgain = true; path.Claim(this); if (path.error) { path.Release(this, false); } else { if (this.path != null) { this.path.Release(this, false); } this.path = path; this.currentWaypointIndex = 0; this.targetReached = false; if (this.closestOnPathCheck) { Vector3 currentPosition = ((Time.time - this.lastFoundWaypointTime) >= 0.3f) ? path.originalStartPoint : this.lastFoundWaypointPosition; Vector3 vector3 = this.GetFeetPosition() - currentPosition; float magnitude = vector3.magnitude; vector3 = (Vector3)(vector3 / magnitude); int num2 = (int)(magnitude / this.pickNextWaypointDist); for (int i = 0; i <= num2; i++) { this.CalculateVelocity(currentPosition); currentPosition += vector3; } } } }
public virtual void OnPathComplete(Path _p) { ABPath abpath = _p as ABPath; if (abpath == null) { throw new Exception("This function only handles ABPaths, do not use special path types"); } this.canSearchAgain = true; abpath.Claim(this); if (abpath.error) { abpath.Release(this); return; } if (this.path != null) { this.path.Release(this); } this.path = abpath; this.currentWaypointIndex = 0; this.targetReached = false; if (this.closestOnPathCheck) { Vector3 vector = (Time.time - this.lastFoundWaypointTime >= 0.3f) ? abpath.originalStartPoint : this.lastFoundWaypointPosition; Vector3 feetPosition = this.GetFeetPosition(); Vector3 vector2 = feetPosition - vector; float magnitude = vector2.magnitude; vector2 /= magnitude; int num = (int)(magnitude / this.pickNextWaypointDist); for (int i = 0; i <= num; i++) { this.CalculateVelocity(vector); vector += vector2; } } }
// Token: 0x06002760 RID: 10080 RVA: 0x001ADE98 File Offset: 0x001AC098 protected override void OnPathComplete(Path _p) { ABPath abpath = _p as ABPath; if (abpath == null) { throw new Exception("This function only handles ABPaths, do not use special path types"); } this.waitingForPathCalculation = false; abpath.Claim(this); if (abpath.error) { abpath.Release(this, false); return; } if (this.path != null) { this.path.Release(this, false); } this.path = abpath; this.currentWaypointIndex = 0; base.reachedEndOfPath = false; if (this.closestOnPathCheck) { Vector3 vector = (Time.time - this.lastFoundWaypointTime < 0.3f) ? this.lastFoundWaypointPosition : abpath.originalStartPoint; Vector3 vector2 = this.GetFeetPosition() - vector; float magnitude = vector2.magnitude; vector2 /= magnitude; int num = (int)(magnitude / this.pickNextWaypointDist); for (int i = 0; i <= num; i++) { this.CalculateVelocity(vector); vector += vector2; } } }
public override void OnPathComplete(Path _p) { if (this._self.roleAction != null && !_p.error) { this._self.roleAction.SetRoleMove(this.walkType); } ABPath aBPath = _p as ABPath; if (aBPath == null) { throw new Exception("This function only handles ABPaths, do not use special path types"); } this.canSearchAgain = true; aBPath.Claim(this); if (aBPath.error) { aBPath.Release(this, false); return; } this.currentWaypointIndex = 0; this.targetReached = false; if (this.path != null) { this.currentWaypointIndex = 1; this.path.Release(this, false); } this.path = aBPath; if (this._self.entityType == RoleManager.EntityType.EntityType_Self) { this._self.roleState.AddState(256); } if (this.path.vectorPath.Count == 0) { Debug.LogError("find path error: path count is 0"); } }
void OnPathComplete(Path newPath) { //异步操作,如果当前这个组件已经enabled = false就不继续往下执行了 if (!enabled) { return; } ABPath p = newPath as ABPath; if (p == null) { throw new System.Exception("This function only handles ABPaths, do not use special path types"); } p.Claim(this); //如果最后一个点不能到达目标点的话,那么玩家跑到最后一个点 //这样的话就不用删除最后能直达目标点的路径点 //默认能够到最后目标点 bool lastEndPointToTarget = true; //和上一次算的路径一样时 if (SamePath(p)) { //路径点目标点一样,不需要继续 if (endNavPoint == p.originalEndPoint) { return; } if (endPathPoint == endNavPoint) { //上一次寻路的目标点是路点路径的最后一个点时 //应该是路点路径的最后一个点不能到目标点 lastEndPointToTarget = NavHelper.CanReachPoint(p.vectorPath[p.vectorPath.Count - 1], p.originalEndPoint, canReachPointLst); if (lastEndPointToTarget) { //继续接下来的计算 } else { //同样不能到,继续跑最后的点 return; } } else { //当正好走到最后一个点时,最后一个点更新 if (segmentIndex == totalPathPoints.Count - 1) { endNavPoint = p.originalEndPoint; totalPathPoints[totalPathPoints.Count - 1] = p.originalEndPoint; _navmeshAgent.SetDestination(p.originalEndPoint); } else { //还没到最后一个点直接替换就可以了 totalPathPoints[totalPathPoints.Count - 1] = p.originalEndPoint; } return; } } if (p.vectorPath.Count <= 0) { waitingForPathCalculation = false; p.Release(this); //当前路径不可达 pathRemainingDistance = -9999; return; } else if (p.vectorPath.Count == 1 || (p.vectorPath.Count == 2 && (p.vectorPath[0] == p.vectorPath[1]))) { totalPathPoints.Clear(); totalPathPoints.Add(p.vectorPath[0]); endPathPoint = p.vectorPath[0]; } else { endPathPoint = p.vectorPath[p.vectorPath.Count - 1]; //如果最后一个点不能到达目标点的话,那么玩家跑到最后一个点 //这样的话就不用删除最后能直达目标点的路径点 if (canReachPointLst == null) { canReachPointLst = NavHelper.GetEmptyPath(); } lastEndPointToTarget = NavHelper.CanReachPoint(p.vectorPath[p.vectorPath.Count - 1], p.originalEndPoint, canReachPointLst); //按照路径点计算到目标点起始点 //如果中间点能直接到目标点或起始点 //删除中间点 if ((AstarPathGo.Instance.pointNavSetting & AstarPathGo.PointNavModel.NAV_OPEN_MIDDLE_DIRECT_REACH) != 0) { int startPoint = FindFirstPoint(p); int endPoint = FindEndPoint(p); if (lastEndPointToTarget) { //能直接到达目标点的最早一个点 if (endPoint < p.vectorPath.Count - 1) { p.vectorPath.RemoveRange(endPoint + 1, p.vectorPath.Count - (endPoint + 1)); } } // if (startPoint > 0) { //能清除的点有重叠,要保留一个 if (startPoint >= p.vectorPath.Count - 1) { Vector3 lastPoint = p.vectorPath[p.vectorPath.Count - 1]; p.vectorPath.Clear(); p.vectorPath.Add(lastPoint); } else { p.vectorPath.RemoveRange(0, startPoint); } } } #region 路点偏移 if (randomRadius > 0) { /// 暂时不做路径点偏移 //float tempRadius = UnityEngine.Random.Range(0, randomRadius); //float angle = UnityEngine.Random.Range(0, 2 * Mathf.PI); ////第一个点不做偏移 //for (int i = 1; i < p.vectorPath.Count; i++) //{ // //float angle = UnityEngine.Random.Range(0, 2 * Mathf.PI); // p.vectorPath[i] = p.vectorPath[i] + new Vector3(Mathf.Cos(angle) * tempRadius, 0, Mathf.Sin(angle) * tempRadius); //} totalPathPoints.Clear(); for (int i = 0; i < p.vectorPath.Count; i++) { totalPathPoints.Add(p.vectorPath[i]); } } #endregion } //起始位置附近的点,如果在其实半径范围内计算目标,选离目标最近的 if (AstarPathGo.Instance.startPointCalc > 0 && totalPathPoints.Count > 0) { Vector3 pathEndPoint = p.originalEndPoint; if (!lastEndPointToTarget) { pathEndPoint = totalPathPoints[totalPathPoints.Count - 1]; } float min = 99999999999; int minIndex = -1; for (int i = 0; i < totalPathPoints.Count; i++) { Vector3 dis_end = pathEndPoint - totalPathPoints[i]; Vector3 dis_start = totalPathPoints[i] - p.originalStartPoint; if (!AstarPathGo.Instance.calcY) { dis_end.y = 0; dis_start.y = 0; } float curDis = Vector3.SqrMagnitude(dis_end); //如果点在范围起始范围之内,才剔除 if (Vector3.SqrMagnitude(dis_start) < AstarPathGo.Instance.SqrStartPointCalc && curDis < min) { if (AstarPathGo.Instance.calcStartCanReach) { if (NavHelper.FastRaycast(totalPathPoints[i], p.originalStartPoint)) { min = curDis; minIndex = i; } } else { min = curDis; minIndex = i; } } } //将离目标最近的点移除 if (minIndex > 0) { totalPathPoints.RemoveRange(0, minIndex + 1); } } p.Release(this); _hasPath = true; if (lastEndPointToTarget) { //添加目标点给路点 totalPathPoints.Add(p.originalEndPoint); } #region 折返处理 if ((AstarPathGo.Instance.pointNavSetting & AstarPathGo.PointNavModel.NAV_OPEN_POINT_FIRST_END_DEL) != 0) { //最后再做折返处理的 if (totalPathPoints.Count >= 2) { float point_Angle = Vector3.Angle(totalPathPoints[1] - totalPathPoints[0], p.originalStartPoint - totalPathPoints[0]); if (point_Angle <= 90) { totalPathPoints.RemoveAt(0); } } if (totalPathPoints.Count >= 2) { float point_Angle = 360; if (totalPathPoints.Count == 2) { point_Angle = Vector3.Angle(totalPathPoints[totalPathPoints.Count - 1] - totalPathPoints[totalPathPoints.Count - 2], p.originalStartPoint - totalPathPoints[totalPathPoints.Count - 2]); } else { point_Angle = Vector3.Angle(totalPathPoints[totalPathPoints.Count - 1] - totalPathPoints[totalPathPoints.Count - 2], totalPathPoints[totalPathPoints.Count - 3] - totalPathPoints[totalPathPoints.Count - 2]); } if (point_Angle <= 90) { totalPathPoints.RemoveAt(totalPathPoints.Count - 2); } } } #endregion endNavPoint = totalPathPoints[totalPathPoints.Count - 1]; #if UNITY_EDITOR _astarSeeker.lastCompletedVectorPath = totalPathPoints; #endif waitingForPathCalculation = false; SetSegmentIndex(0); }
/// <summary> /// Called when a requested path has finished calculation. /// A path is first requested by <see cref="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. /// </summary> protected 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; // Increase the reference count on the path. // This is used for path pooling 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; } if (interpolatePathSwitches) { ConfigurePathSwitchInterpolation(); } // Replace the old path var oldPath = path; path = p; reachedEndOfPath = false; // Just for the rest of the code to work, if there // is only one waypoint in the path add another one if (path.vectorPath != null && path.vectorPath.Count == 1) { path.vectorPath.Insert(0, GetFeetPosition()); } // Reset some variables ConfigureNewPath(); // Release the previous path // This is used for path pooling. // This is done after the interpolator has been configured in the ConfigureNewPath method // as this method would otherwise invalidate the interpolator // since the vectorPath list (which the interpolator uses) will be pooled. if (oldPath != null) { oldPath.Release(this); } if (interpolator.remainingDistance < endReachedDistance && !reachedEndOfPath) { reachedEndOfPath = true; OnTargetReached(); } }
/** 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) { // bSearchStart = false; 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 // This is used for path pooling p.Claim(this); // Path couldn't be calculated of some reason. // More info in p.errorLog (debug string) if (p.error) { p.Release(this); //unit if (unitController != null) { unitController.TargetFindandPathSearch(EntityType.Defense); } return; } if (interpolatePathSwitches) { ConfigurePathSwitchInterpolation(); } // Release the previous path // This is used for path pooling if (path != null) { path.Release(this); } // Replace the old path path = p; // Just for the rest of the code to work, if there is only one waypoint in the path // add another one if (path.vectorPath != null && path.vectorPath.Count == 1) { path.vectorPath.Insert(0, GetFeetPosition()); } targetReached = false; //unit if (unitController != null) { unitController.OnTargetFind(); } // Reset some variables ConfigureNewPath(); }
/// <summary> /// Called when a requested path has finished calculation. /// A path is first requested by <see cref="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 /// </summary> protected override 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"); } waitingForPathCalculation = false; //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; //Reset some variables currentWaypointIndex = 0; reachedEndOfPath = false; //The next row can be used to find out if the path could be found or not //If it couldn't (error == true), then a message has probably been logged to the console //however it can also be got using p.errorLog //if (p.error) if (closestOnPathCheck) { // 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). Vector3 p1 = Time.time - lastFoundWaypointTime < 0.3f ? lastFoundWaypointPosition : p.originalStartPoint; Vector3 p2 = GetFeetPosition(); Vector3 dir = p2 - p1; float magn = dir.magnitude; dir /= magn; int steps = (int)(magn / pickNextWaypointDist); #if ASTARDEBUG Debug.DrawLine(p1, p2, Color.red, 1); #endif for (int i = 0; i <= steps; i++) { CalculateVelocity(p1); p1 += dir; } } }