How to make more realistic bot AI?

It appears that I have accidentally programmed magnetic repulsion.

I’m trying to make one circle (the bot) move away from another circle (the player). Unfortunately the bot is WAY too responsive and it is impossible for the player to get to the bot. Also it looks completely unrealistic, as I want to create the illusion that it is in fact running away.

Any help would be greatly appreciated.

void Fleeing() {

	Vector3 direction = transform.position - Player.transform.position;
	direction.Normalize();
	
	Move (direction);
}

void Move(Vector3 direction) {

	transform.position = Vector3.MoveTowards (transform.position, direction, speed * Time.deltaTime / transform.localScale.x);
}

Easiest way would be to create a Trigger collider 2d (or use a raycast), set a “range” (the size of the collider, or length of the raycast shot, forward), and use the OnTriggerEnter2D method - so if the player happens to be within that “range” of the bot, then it wil activate “fleeing”, and you can either use a timer in OnTriggerExit2D, after for example, 3 seconds, the bot will change from “fleeing” to “idle” or whatever - or the bot will constantly check the distance it is from the player, and once its a certain “safe” distance, itll change states.

You could also add a “cone of sight” instead, so that it will only flee if it happens to be looking in the players general direction AND the player is within the cone of sight, then use a timer so that after x seconds, itll check if its “safe” by turning around or just simply slowing down, until the player triggers to go into flee again - pretty much the same way that Spores Cell AI works.

Instead of using the exact direction to the player, you could add some randomness in the fleeing direction.

In general, making the AI more realistic would mean to add some subtle complexities to the AI behaviour, such as making some pauses from time to time, as if the AI is evaluating the situation. That would make it less reactive.

Behaviour Tree (BT) is a good tool that make it easier to develop complex AIs. I’m the author of Panda BT, a scripting framework based on Behaviour Tree. Have a look at this demo, which illustrates an AI playing Tag (the children game) with the player. The AI will try to run away from player when the player is “It”. Which could give you some inspiration to implement your escaping behaviour.