/** Calculates target point from the current line segment. * \param p Current position * \param a Line segment start * \param b Line segment end * The returned point will lie somewhere on the line segment. * \see #forwardLook * \todo This function uses .magnitude quite a lot, can it be optimized? */ protected Vector3 CalculateTargetPoint(Vector3 p, Vector3 a, Vector3 b) { if (entity == null || entity.MoveState != Pathea.MovementState.Water) { a.y = p.y; b.y = p.y; } float magn = (a - b).magnitude; if (magn == 0) { return(a); } float closest = AstarMath.Clamp01(AstarMath.NearestPointFactor(a, b, p)); Vector3 point = (b - a) * closest + a; float distance = (point - p).magnitude; float lookAhead = Mathf.Clamp(forwardLook - distance, 0.0F, forwardLook); float offset = lookAhead / magn; offset = Mathf.Clamp(offset + closest, 0.0F, 1.0F); return((b - a) * offset + a); }
protected Vector3 CalculateTargetPoint(Vector3 p, Vector3 a, Vector3 b) { a.y = p.y; b.y = p.y; float magn = (a - b).magnitude; if (magn == 0) return a; float closest = AstarMath.Clamp01(AstarMath.NearestPointFactor(a, b, p)); Vector3 point = (b - a) * closest + a; float distance = (point - p).magnitude; float lookAhead = Mathf.Clamp(forwardLook - distance, 0.0F, forwardLook); float offset = lookAhead / magn; offset = Mathf.Clamp(offset + closest, 0.0F, 1.0F); return (b - a) * offset + a; }
protected Vector3 CalculateTargetPoint(Vector3 p, Vector3 a, Vector3 b, bool canGoDirectly) { if (canGoDirectly && (b - this.target.position).sqrMagnitude < 16f) { return(this.target.position); } a.y = p.y; b.y = p.y; float magnitude = (a - b).magnitude; if (magnitude == 0f) { return(a); } float num = AstarMath.Clamp01(AstarMath.NearestPointFactor(a, b, p)); Vector3 vector = (b - a) * num + a; float magnitude2 = (vector - p).magnitude; float num2 = Mathf.Clamp(this.forwardLook - magnitude2, 0f, this.forwardLook); float num3 = num2 / magnitude; num3 = Mathf.Clamp(num3 + num, 0f, 1f); return((b - a) * num3 + a); }