Search Unity

Question Make the enemy follow the Player

Discussion in 'Scripting' started by yrmrtn, Aug 2, 2022.

  1. yrmrtn

    yrmrtn

    Joined:
    Feb 2, 2021
    Posts:
    2
    Hello! I'm trying to create a chase game in which the Player has to reach a finish line without getting caught by the enemy while avoiding some obstacles. Up to this point I've programmed the enemy to follow the player using (player.transform.position - transform.position).normalized and now I've got three questions:
    1. Is there any better, more efficient way to make the enemy follow the Player?
    2. How can I make the enemy ignore the obstacles (so it can follow the Player without getting stuck and being left behind) while still chasing the Player effectively?
    3. Using what bit of code can I program the enemy to face the Player while chasing it? Because, at the moment, when the Player turns around a corner, the enemy rotation doesn't change, so you end up with an enemy awkwardly chasing you sideways or backwards (I'll attach an image for that).
    If you can, please answer my questions as quickly as possible because I need to implement all these in my game and finish as soon as possible, because my deadline is strict and there's only two weeks left. Thank you in advance for your help!
    unity bug.jpg
     
  2. Terraya

    Terraya

    Joined:
    Mar 8, 2018
    Posts:
    646
    NavMeshAgent is the way to go here
     
  3. yrmrtn

    yrmrtn

    Joined:
    Feb 2, 2021
    Posts:
    2
    How can I use NavMeshAgent here? Because I've never used it before
     
  4. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,639