Help with fleePath

I was wondering how do you turn this into a vectorPath?
Vector2 direction = FleePath.Construct(transform.position, playerTransform.position, 1);

// Call a FleePath call like this, assumes that a Seeker is attached to the GameObject
Vector3 thePointToFleeFrom = Vector3.zero;

// The path will be returned when the path is over a specified length (or more accurately when the traversal cost is greater than a specified value).
// A score of 1000 is approximately equal to the cost of moving one world unit.
int theGScoreToStopAt = 10000;

// Create a path object
FleePath path = FleePath.Construct (transform.position, thePointToFleeFrom, theGScoreToStopAt);
// This is how strongly it will try to flee, if you set it to 0 it will behave like a RandomPath
path.aimStrength = 1;
// Determines the variation in path length that is allowed
path.spread = 4000;

// Get the Seeker component which must be attached to this GameObject
Seeker seeker = GetComponent<Seeker>();

// Start the path and return the result to MyCompleteFunction (which is a function you have to define, the name can of course be changed)
seeker.StartPath(path, OnPathComplete);
// This will be called when the path has been calculated
void OnPathComplete(Path p) {
    var path = p as FleePath;
    Debug.Log(path.vectorPath.Length);
}

See https://arongranberg.com/astar/docs/callingpathfinding.html for more information about how to calculate paths, e.g. how to do it synchronously instead of asynchronously.

I usually just calculate my Path by making a Vector 2 and then using it into an rigidbody2D.AddForce and I just need a way to convert it into one. Also on the Page they mentioned they didn’t really give you an example so thats why I am asking here, so yeah if you do know how to convert it please reply

Hi

A Vector2 is just a single vector, not a path. So I’m not quite sure what you mean.

Ok, then let me re-phrase my question. Is there a way I can convert the calculated path by the fleePath into an X and Y vector for my object to follow.

You might be interested in this tutorial: https://arongranberg.com/astar/docs/custom_movement_script.html
It’s a very simple script, but it’s a start.

Oh ok thx but I already made a part of script that makes the object follow the player without hitting anything. The thing is I just want to do the opposite so that is why I am using fleePath. Also I am using Vectors cause this is how I did it with the part of the script that makes the object follow the player.

Vector2 direction = ((Vector2)path.vectorPath[currentWaypoint] - rigidbody2D.position).normalized;

Yes. You do the exact same thing with a FleePath. A FleePath is just like a normal path, it’s just calculated slightly differently.

Oh ok its just when I do this it gives me an error
Vector2 direction = (Vector2)FleePath.vectorPath(transform.position, playerTransform.position, 1)

error CS1955: Non-invocable member 'Path.vectorPath' cannot be used like a method.

FleePath is the class name. Please take a look at the first code snippet I posted.

1 Like

Ok then should it be like any one of these:

  1. FleePath vectorPath
  2. FleePath path.vectorPath
  3. path.vectorPath

(Also you were talking about your first reply right?)

path.vectorPath

You seem to be a beginner with the C# language. I’d recommend trying out some C# tutorials to get a better feel for it. Things will go much easier then :slight_smile:

1 Like

Yeah I am and ok, still thx for the help! :+1: