I want to move the enemy away from my player, but I don't know how.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By OiKeTTLe

I want the enemy to stay a set distance away from the player, and move away when the player breaches that distance. I’m not sure how to set this up. Any ideas on how to achieve this?

:bust_in_silhouette: Reply From: Thomas Karcher

Set up an Area2D object with a large collision circle around the enemy, which will be the “fleeing distance”. Once the player enters this Area, the enemy can switch to a “fleeing” mode, moving away from the player until the Area is free again.

I created a small demo for this: