// ---------------------------------------------------------------------------- // 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 mapReturnStruct tStruct = new mapReturnStruct(); 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)); } }
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)); }
// ---------------------------------------------------------------------------- // 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 mapReturnStruct tStruct = new mapReturnStruct(); 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); } }
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); } }