Topic was automatically imported from the old Question2Answer platform.
Asked By
zen3001
I know how to find paths and make ai chase a target (or the player) with either astar or the standard navigation but how do you find a path to run away from a target?
To run away from something, you can run towards a target that is far away, like a corner of your level.
Alternatively, if the AI is scarred, you could just have it go in the opposite direction of what it is scarred of, until it hits a wall head first.
thought about this before but how would I find out these cornor positions?
zen3001 | 2021-02-03 18:14
Hi, I have somthing like this:
public void TouchByLight(Light3D light)
{
if (State != EnemyState.ESCAPE)
{
State = EnemyState.ESCAPE;
Vector3 direction = new Vector3(
light.GlobalTransform.origin.x - GlobalTransform.origin.x,
0f,
light.GlobalTransform.origin.z - GlobalTransform.origin.z
).Normalized();
Target = GlobalTransform.origin + direction * ESCAPE_DISTANCE;
}
}
This should work as you say, but the AI run to a random direction in this case, have you any Idea of what I could doing wrong here?