protected Vector3 CalculateVelocity(Vector3 currentPosition) { if (this.path == null || this.path.vectorPath == null || this.path.vectorPath.Count == 0) { return Vector3.zero; } List<Vector3> vectorPath = this.path.vectorPath; if (vectorPath.Count == 1) { vectorPath.Insert(0, currentPosition); } if (this.currentWaypointIndex >= vectorPath.Count) { this.currentWaypointIndex = vectorPath.Count - 1; } if (this.currentWaypointIndex <= 1) { this.currentWaypointIndex = 1; } while (this.currentWaypointIndex < vectorPath.Count - 1) { float num = VectorMath.SqrDistanceXZ(vectorPath[this.currentWaypointIndex], currentPosition); if (num >= this.pickNextWaypointDist * this.pickNextWaypointDist) { break; } this.lastFoundWaypointPosition = currentPosition; this.lastFoundWaypointTime = Time.time; this.currentWaypointIndex++; } Vector3 vector = vectorPath[this.currentWaypointIndex - 1]; Vector3 vector2 = vectorPath[this.currentWaypointIndex]; float num2 = VectorMath.LineCircleIntersectionFactor(AIPath.To2D(currentPosition), AIPath.To2D(vector), AIPath.To2D(vector2), this.pickNextWaypointDist); num2 = Mathf.Clamp01(num2); Vector3 a = Vector3.Lerp(vector, vector2, num2); Vector3 vector3 = a - currentPosition; vector3.y = 0f; float magnitude = vector3.magnitude; float num3 = (this.slowdownDistance <= 0f) ? 1f : Mathf.Clamp01(magnitude / this.slowdownDistance); this.targetDirection = vector3; this.targetPoint = a; if (this.currentWaypointIndex == vectorPath.Count - 1 && magnitude <= this.endReachedDistance) { if (!this.targetReached) { this.targetReached = true; this.OnTargetReached(); } return Vector3.zero; } Vector3 forward = this.tr.forward; float a2 = Vector3.Dot(vector3.normalized, forward); float num4 = this.speed * Mathf.Max(a2, this.minMoveScale) * num3; if (Time.deltaTime > 0f) { num4 = Mathf.Clamp(num4, 0f, magnitude / (Time.deltaTime * 2f)); } return forward * num4; }