How do i make a AI enemy that go to player and if enemy arrives at collision (ex. stone collider) rotating to path , (unity 2D top view)?enter image description here

(Enemy has a face sprite and animator component) In this pic , I want to do :ai enemy following player but when arrives to wall so it's face changes the path and following again . 2- if enemy 1 arrives to enemy2 so enemy face change the path for follow player


closed as too broad by Philipp, Alexandre Vaillancourt, Tyyppi_77, DMGregory, Gnemlock Nov 18 '17 at 23:09

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    \$\begingroup\$ Please show us what you have tried and tell us why did not work. \$\endgroup\$ – Alexandre Vaillancourt Nov 7 '17 at 11:05
  • 2
    \$\begingroup\$ Man, this looks more like a google search than something you should type in as a question... \$\endgroup\$ – Alakanu Nov 7 '17 at 14:13
  • \$\begingroup\$ Hi pezhy! I notice this question has come up in the review queue due to some close votes. Because there are many different ways to approach AI that chase the player, adding more detail to your question can help narrow down the cases to a useful scope. For instance, can you show us what your typical levels look like? If they have long walls or maze shapes, you might need pathfinding, but if they just have isolated obstacles we can get away with simple avoidance. Other useful details include when the AI should start chasing (eg. from any distance, or only when they're close/in line of sight?) \$\endgroup\$ – DMGregory Nov 7 '17 at 17:47

You have multiple challenges baked into one here:

  1. Get an enemy to chase the player
  2. Get an enemy to respect the other objects in your scene
  3. Have the enemy find a valid path around the object

The first two are quite simple to get working, the third requires a more complex solution, either using ray-casting for very simple scenarios, or actual path-finding such as A* maps or similar. In this latter case, implementing it is quire a lot more tricky.

Either way, I would recommend you do some more searching on the first two, there are plenty of solutions to this problem already. I did a quick search and found these:

chase player: https://answers.unity.com/questions/274809/how-to-make-enemy-chase-player-basic-ai.html

for changing direction: https://answers.unity.com/questions/284206/change-direction-on-collision-problem-1.html

There are also a lot of basic tutorials on these on youtube. Either way, you can't simply copy paste a solution, as you will need to understand what is unique to your game world.

  • \$\begingroup\$ Marius thanks a lot. So I need to combine both scripts a bove but them were java scripts , I don't know java . I want to do c# script \$\endgroup\$ – pezhy Nov 7 '17 at 18:16

Not the answer you're looking for? Browse other questions tagged or ask your own question.