示例#1
0
        // ----------------------------------------------------------------------------
        // Path Following behaviors

        public Vector3 steerToStayOnPath(float predictionTime, Pathway path)
        {
            // predict our future position
            Vector3 futurePosition = predictFuturePosition(predictionTime);

            // find the point on the path nearest the predicted future position
            PathRelativePosition tStruct = new PathRelativePosition();

            Vector3 onPath = path.MapPointToPath(futurePosition, ref tStruct);

            if (tStruct.outside < 0)
            {
                // our predicted future position was in the path,
                // return zero steering.
                return(Vector3.zero);
            }
            else
            {
                // our predicted future position was outside the path, need to
                // steer towards it.  Use onPath projection of futurePosition
                // as seek target
                                #if ANNOTATE_PATH
                annotatePathFollowing(futurePosition, onPath, onPath, tStruct.outside);
                                #endif
                return(steerForSeek(onPath));
            }
        }
示例#2
0
 /// <summary>
 /// Builds a PathFollower from a rigidbody
 /// </summary>
 /// <param name="rigidbody">
 /// A rigidbody to be updated and from whom the mass is taken <see cref="Rigidbody"/>
 /// </param>
 /// <param name="pathway">
 /// Pathway to follow <see cref="Pathway"/>
 /// </param>
 /// <param name="radius">
 /// Vehicle radius <see cref="System.Single"/>
 /// </param>
 public PathFollower(Rigidbody rigidbody, Pathway pathway, float radius)
     : base(rigidbody)
 {
     reset();
     this.Pathway  = pathway;
     this.Radius   = radius;
 }
示例#3
0
 /// <summary>
 /// Builds a PathFollower from a transform
 /// </summary>
 /// <param name="transform">
 /// Transform that the vehicle will update <see cref="Transform"/>
 /// </param>
 /// <param name="mass">
 /// Vehicle mass, for acceleration calculations <see cref="System.Single"/>
 /// </param>
 /// <param name="pathway">
 /// Pathway to follow <see cref="Pathway"/>
 /// </param>
 /// <param name="radius">
 /// Vehicle radius <see cref="System.Single"/>
 /// </param>
 public PathFollower(Transform transform, float mass, Pathway pathway, float radius)
     : base(transform, mass)
 {
     reset();
     this.Pathway  = pathway;
     this.Radius   = radius;
 }
        public Vector3 steerToStayOnPath(float predictionTime, Pathway path)
        {
            Vector3         vector          = this.predictFuturePosition(predictionTime);
            mapReturnStruct mapReturnStruct = default(mapReturnStruct);
            Vector3         vector2         = path.mapPointToPath(vector, ref mapReturnStruct);

            if (mapReturnStruct.outside < 0f)
            {
                return(Vector3.get_zero());
            }
            this.annotatePathFollowing(vector, vector2, vector2, mapReturnStruct.outside);
            return(this.steerForSeek(vector2));
        }
示例#5
0
 public void SetPath( Pathway path, float weight )
 {
     Path = path;
     SteerToStayOnPathWeight = weight;
 }
		// ----------------------------------------------------------------------------
		// Path Following behaviors

		public Vector3 steerToStayOnPath(float predictionTime, Pathway path)
		{
			// predict our future position
			Vector3 futurePosition = predictFuturePosition (predictionTime);

			// find the point on the path nearest the predicted future position
			PathRelativePosition tStruct = new PathRelativePosition();

			Vector3 onPath = path.MapPointToPath(futurePosition, ref tStruct);

			if (tStruct.outside < 0)
			{
				// our predicted future position was in the path,
				// return zero steering.
				return Vector3.zero;
			}
			else
			{
				// our predicted future position was outside the path, need to
				// steer towards it.  Use onPath projection of futurePosition
				// as seek target
				#if ANNOTATE_PATH
				annotatePathFollowing (futurePosition, onPath, onPath,tStruct.outside);
				#endif
				return steerForSeek (onPath);
			}
		}
示例#7
0
		public Vector3 steerToFollowPath(int direction, float predictionTime, Pathway path)
		{
			// our goal will be offset from our path distance by this amount
			float pathDistanceOffset = direction * predictionTime * Speed;

			// predict our future position
			Vector3 futurePosition = predictFuturePosition (predictionTime);
			
			// measure distance along path of our current and predicted positions
			float nowPathDistance =
				path.mapPointToPathDistance (Position);
			float futurePathDistance =
				path.mapPointToPathDistance (futurePosition);

			// are we facing in the correction direction?
			bool rightway = ((pathDistanceOffset > 0) ?
								   (nowPathDistance < futurePathDistance) :
								   (nowPathDistance > futurePathDistance));

			// find the point on the path nearest the predicted future position
			// XXX need to improve calling sequence, maybe change to return a
			// XXX special path-defined object which includes two Vector3s and a 
			// XXX bool (onPath,tangent (ignored), withinPath)
			mapReturnStruct tStruct = new mapReturnStruct();
			Vector3 onPath = path.mapPointToPath(futurePosition, ref tStruct);

			// no steering is required if (a) our future position is inside
			// the path tube and (b) we are facing in the correct direction
			if ((tStruct.outside < 0) && rightway)
			{
				// all is well, return zero steering
				return Vector3.zero;
			}
			else
			{
				// otherwise we need to steer towards a target point obtained
				// by adding pathDistanceOffset to our current path position

				float targetPathDistance = nowPathDistance + pathDistanceOffset;
				Vector3 target = path.mapPathDistanceToPoint (targetPathDistance);

				#if ANNOTATE_PATH
				annotatePathFollowing(futurePosition, onPath, target, tStruct.outside);
				//Debug.DrawLine(Position, path.LastPoint, Color.green);
				#endif

				// return steering to seek target on path
				return steerForSeek (target);
			}
		}