Automatic enemy movement and change of direction

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

Hello, I am trying to make the red circle move automatically, to either side … and that when it collides with the Player’s Area2D, it chooses another direction, why should it collide with this … idea would be that he run away and that if he approaches him … look for another direction to get away

Here is the image of the project so that they understand me:https://imgur.com/a/Rq8xg5L

Well, it is difficult to understand, first, it looks like the link to your image is chashed and I had to type it. Second, I usually use vector maths to solve enemies behavior, so, you can first add a script to your enemy to make it more organized. That way you can get the player position and set it as a target, so your enemy will go towards player, when enemy hits player’s area2D you can use a flag and change the state of the enemy behavior and go away. It can be confusing but let me know if you would like to get this solution and I can explain it better.

stevkastt | 2020-05-09 19:44