This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
+1 vote

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?

Godot version 3.2.2
in Engine by (307 points)

2 Answers

+3 votes
Best answer

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.

by (2,720 points)
selected by

thought about this before but how would I find out these cornor positions?

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?

+1 vote

Hi, after I struggle by myself with this problem, I finally end with this solution:

 public void TouchByLight(Node3D escapeFrom)
{
        Vector3 direction = GlobalTransform.origin.DirectionTo(escapeFrom.GlobalTransform.origin);
        Vector3 target = GlobalTransform.origin - direction * ESCAPE_DISTANCE;
        target.y = GlobalTransform.origin.y;
        Target = target;
    }

}

Hope this help

by (18 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.