Exemplo n.º 1
0
        public void MoveToCircleIntersection2D(Vector3 circleCenter3D, float radius, IMovementPlane transform)
        {
            if (path == null)
            {
                return;
            }

            // Move forwards as long as we are getting closer to circleCenter3D
            while (segmentIndex < path.Count - 2 && VectorMath.ClosestPointOnLineFactor(path[segmentIndex], path[segmentIndex + 1], circleCenter3D) > 1)
            {
                NextSegment();
            }

            var circleCenter = transform.ToPlane(circleCenter3D);

            // Move forwards as long as the current segment endpoint is within the circle
            while (segmentIndex < path.Count - 2 && (transform.ToPlane(path[segmentIndex + 1]) - circleCenter).sqrMagnitude <= radius * radius)
            {
                NextSegment();
            }

            // Calculate the intersection with the circle. This involves some math.
            var factor = VectorMath.LineCircleIntersectionFactor(circleCenter, transform.ToPlane(path[segmentIndex]), transform.ToPlane(path[segmentIndex + 1]), radius);

            // Move to the intersection point
            MoveToSegment(segmentIndex, factor);
        }
Exemplo n.º 2
0
	protected virtual void ConfigureNewPath()
	{
		List<Vector3> vectorPath = this.path.vectorPath;
		Vector3 feetPosition = this.GetFeetPosition();
		float num = 0f;
		float num2 = float.PositiveInfinity;
		Vector3 vector = Vector3.zero;
		int num3 = 1;
		for (int i = 0; i < vectorPath.Count - 1; i++)
		{
			float num4 = VectorMath.ClosestPointOnLineFactor(vectorPath[i], vectorPath[i + 1], feetPosition);
			num4 = Mathf.Clamp01(num4);
			Vector3 b = Vector3.Lerp(vectorPath[i], vectorPath[i + 1], num4);
			float sqrMagnitude = (feetPosition - b).sqrMagnitude;
			if (sqrMagnitude < num2)
			{
				num2 = sqrMagnitude;
				vector = vectorPath[i + 1] - vectorPath[i];
				num = num4 * vector.magnitude;
				num3 = i + 1;
			}
		}
		this.currentWaypointIndex = num3;
		this.distanceAlongSegment = num;
		if (this.interpolatePathSwitches && this.switchPathInterpolationSpeed > 0.01f)
		{
			float num5 = Mathf.Max(-Vector3.Dot(this.previousMovementDirection.normalized, vector.normalized), 0f);
			this.distanceAlongSegment -= this.speed * num5 * (1f / this.switchPathInterpolationSpeed);
		}
	}
Exemplo n.º 3
0
        /** Move as close as possible to the specified point */
        public void MoveToClosestPoint(Vector3 point)
        {
            if (path == null)
            {
                return;
            }

            float bestDist   = float.PositiveInfinity;
            float bestFactor = 0f;
            int   bestIndex  = 0;

            for (int i = 0; i < path.Count - 1; i++)
            {
                float   factor  = VectorMath.ClosestPointOnLineFactor(path[i], path[i + 1], point);
                Vector3 closest = Vector3.Lerp(path[i], path[i + 1], factor);
                float   dist    = (point - closest).sqrMagnitude;

                if (dist < bestDist)
                {
                    bestDist   = dist;
                    bestFactor = factor;
                    bestIndex  = i;
                }
            }

            MoveToSegment(bestIndex, bestFactor);
        }
Exemplo n.º 4
0
        public void MoveToLocallyClosestPoint(Vector3 point, bool allowForwards = true, bool allowBackwards = true)
        {
            while (allowForwards && this.segmentIndex < this.path.Count - 2 && (this.path[this.segmentIndex + 1] - point).sqrMagnitude <= (this.path[this.segmentIndex] - point).sqrMagnitude)
            {
                this.NextSegment();
            }
            while (allowBackwards && this.segmentIndex > 0 && (this.path[this.segmentIndex - 1] - point).sqrMagnitude <= (this.path[this.segmentIndex] - point).sqrMagnitude)
            {
                this.PrevSegment();
            }
            float num  = 0f;
            float num2 = 0f;
            float num3 = float.PositiveInfinity;
            float num4 = float.PositiveInfinity;

            if (this.segmentIndex > 0)
            {
                num  = VectorMath.ClosestPointOnLineFactor(this.path[this.segmentIndex - 1], this.path[this.segmentIndex], point);
                num3 = (Vector3.Lerp(this.path[this.segmentIndex - 1], this.path[this.segmentIndex], num) - point).sqrMagnitude;
            }
            if (this.segmentIndex < this.path.Count - 1)
            {
                num2 = VectorMath.ClosestPointOnLineFactor(this.path[this.segmentIndex], this.path[this.segmentIndex + 1], point);
                num4 = (Vector3.Lerp(this.path[this.segmentIndex], this.path[this.segmentIndex + 1], num2) - point).sqrMagnitude;
            }
            if (num3 < num4)
            {
                this.MoveToSegment(this.segmentIndex - 1, num);
            }
            else
            {
                this.MoveToSegment(this.segmentIndex, num2);
            }
        }
Exemplo n.º 5
0
    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  = Mathf.Clamp01(VectorMath.ClosestPointOnLineFactor(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);

        Debug.Log(a + b);
    }
        // Token: 0x06002765 RID: 10085 RVA: 0x001AE29C File Offset: 0x001AC49C
        protected Vector3 CalculateTargetPoint(Vector3 p, Vector3 a, Vector3 b)
        {
            a.y = p.y;
            b.y = p.y;
            float magnitude = (a - b).magnitude;

            if (magnitude == 0f)
            {
                return(a);
            }
            float num        = Mathf.Clamp01(VectorMath.ClosestPointOnLineFactor(a, b, p));
            float magnitude2 = ((b - a) * num + a - p).magnitude;
            float num2       = Mathf.Clamp(this.forwardLook - magnitude2, 0f, this.forwardLook) / magnitude;

            num2 = Mathf.Clamp(num2 + num, 0f, 1f);
            return((b - a) * num2 + a);
        }
        public void MoveToLocallyClosestPoint(Vector3 point, bool allowForwards = true, bool allowBackwards = true)
        {
            if (path == null)
            {
                return;
            }

            while (allowForwards && segmentIndex < path.Count - 2 && (path[segmentIndex + 1] - point).sqrMagnitude <=
                   (path[segmentIndex] - point).sqrMagnitude)
            {
                NextSegment();
            }

            while (allowBackwards && segmentIndex > 0 && (path[segmentIndex - 1] - point).sqrMagnitude <=
                   (path[segmentIndex] - point).sqrMagnitude)
            {
                PrevSegment();
            }

            // Check the distances to the two segments extending from the vertex path[segmentIndex]
            // and pick the position on those segments that is closest to the #point parameter.
            float factor1 = 0, factor2 = 0, d1 = float.PositiveInfinity, d2 = float.PositiveInfinity;

            if (segmentIndex > 0)
            {
                factor1 = VectorMath.ClosestPointOnLineFactor(path[segmentIndex - 1], path[segmentIndex], point);
                d1      = (Vector3.Lerp(path[segmentIndex - 1], path[segmentIndex], factor1) - point).sqrMagnitude;
            }

            if (segmentIndex < path.Count - 1)
            {
                factor2 = VectorMath.ClosestPointOnLineFactor(path[segmentIndex], path[segmentIndex + 1], point);
                d2      = (Vector3.Lerp(path[segmentIndex], path[segmentIndex + 1], factor2) - point).sqrMagnitude;
            }

            if (d1 < d2)
            {
                MoveToSegment(segmentIndex - 1, factor1);
            }
            else
            {
                MoveToSegment(segmentIndex, factor2);
            }
        }
Exemplo n.º 8
0
    protected Vector3 CalculateTargetPoint(Vector3 p, Vector3 a, Vector3 b)
    {
        a.y = p.y;
        b.y = p.y;
        Vector3 vector2   = a - b;
        float   magnitude = vector2.magnitude;

        if (magnitude == 0f)
        {
            return(a);
        }
        float   num2    = Mathf.Clamp01(VectorMath.ClosestPointOnLineFactor(a, b, p));
        Vector3 vector  = ((Vector3)((b - a) * num2)) + a;
        Vector3 vector3 = vector - p;
        float   num3    = vector3.magnitude;
        float   num5    = Mathf.Clamp(this.forwardLook - num3, 0f, this.forwardLook) / magnitude;

        num5 = Mathf.Clamp((float)(num5 + num2), (float)0f, (float)1f);
        return(((Vector3)((b - a) * num5)) + a);
    }
Exemplo n.º 9
0
        public void MoveToClosestPoint(Vector3 point)
        {
            float num = float.PositiveInfinity;
            float fractionAlongSegment = 0f;
            int   index = 0;

            for (int i = 0; i < this.path.Count - 1; i++)
            {
                float   num2         = VectorMath.ClosestPointOnLineFactor(this.path[i], this.path[i + 1], point);
                Vector3 b            = Vector3.Lerp(this.path[i], this.path[i + 1], num2);
                float   sqrMagnitude = (point - b).sqrMagnitude;
                if (sqrMagnitude < num)
                {
                    num = sqrMagnitude;
                    fractionAlongSegment = num2;
                    index = i;
                }
            }
            this.MoveToSegment(index, fractionAlongSegment);
        }
        // Token: 0x0600297C RID: 10620 RVA: 0x001C1704 File Offset: 0x001BF904
        public void MoveToCircleIntersection2D(Vector3 circleCenter3D, float radius, IMovementPlane transform)
        {
            if (this.path == null)
            {
                return;
            }
            while (this.segmentIndex < this.path.Count - 2 && VectorMath.ClosestPointOnLineFactor(this.path[this.segmentIndex], this.path[this.segmentIndex + 1], circleCenter3D) > 1f)
            {
                this.NextSegment();
            }
            Vector2 vector = transform.ToPlane(circleCenter3D);

            while (this.segmentIndex < this.path.Count - 2 && (transform.ToPlane(this.path[this.segmentIndex + 1]) - vector).sqrMagnitude <= radius * radius)
            {
                this.NextSegment();
            }
            float fractionAlongSegment = VectorMath.LineCircleIntersectionFactor(vector, transform.ToPlane(this.path[this.segmentIndex]), transform.ToPlane(this.path[this.segmentIndex + 1]), radius);

            this.MoveToSegment(this.segmentIndex, fractionAlongSegment);
        }
Exemplo n.º 11
0
    /** Finds the closest point on the current path.
     * Sets #currentWaypointIndex and #lerpTime to the appropriate values.
     */
    protected virtual void ConfigureNewPath()
    {
        var points = path.vectorPath;

        var currentPosition = GetFeetPosition();

        // Find the closest point on the new path
        // to our current position
        // and initialize the path following variables
        // to start following the path from that point
        float   bestDistanceAlongSegment = 0;
        float   bestDist      = float.PositiveInfinity;
        Vector3 bestDirection = Vector3.zero;
        int     bestIndex     = 1;

        for (int i = 0; i < points.Count - 1; i++)
        {
            float factor = VectorMath.ClosestPointOnLineFactor(points[i], points[i + 1], currentPosition);
            factor = Mathf.Clamp01(factor);
            Vector3 point = Vector3.Lerp(points[i], points[i + 1], factor);
            float   dist  = (currentPosition - point).sqrMagnitude;

            if (dist < bestDist)
            {
                bestDist                 = dist;
                bestDirection            = points[i + 1] - points[i];
                bestDistanceAlongSegment = factor * bestDirection.magnitude;
                bestIndex                = i + 1;
            }
        }

        currentWaypointIndex = bestIndex;
        distanceAlongSegment = bestDistanceAlongSegment;

        if (interpolatePathSwitches && switchPathInterpolationSpeed > 0.01f)
        {
            var correctionFactor = Mathf.Max(-Vector3.Dot(previousMovementDirection.normalized, bestDirection.normalized), 0);
            distanceAlongSegment -= speed * correctionFactor * (1f / switchPathInterpolationSpeed);
        }
    }
Exemplo n.º 12
0
        /// <summary>
        /// Calculates target point from the current line segment.
        /// </summary>
        /// <returns>The target point.</returns>
        /// <param name="_p">_p.</param>
        /// <param name="_a">_a.</param>
        /// <param name="_b">_b.</param>
        protected Vector3 CalculateTargetPoint(Vector3 _position, Vector3 _segment_start, Vector3 _segment_end)
        {
            _segment_start.y = _position.y;
            _segment_end.y   = _position.y;

            float _magnitude = (_segment_start - _segment_end).magnitude;

            if (_magnitude == 0)
            {
                return(_segment_start);
            }


            float   _closest  = Mathf.Clamp01(VectorMath.ClosestPointOnLineFactor(_segment_start, _segment_end, _position));
            Vector3 _point    = (_segment_end - _segment_start) * _closest + _segment_start;
            float   _distance = (_point - _position).magnitude;

            float _look_ahead = Mathf.Clamp(ForwardLook - _distance, 0.0F, ForwardLook);

            float _offset = _look_ahead / _magnitude;

            _offset = Mathf.Clamp(_offset + _closest, 0.0F, 1.0F);
            return((_segment_end - _segment_start) * _offset + _segment_start);
        }