Search Unity

Question How can I make enemy follow a certain path only?

Discussion in 'Navigation' started by anikataylor, Jan 3, 2023.

  1. anikataylor

    anikataylor

    Joined:
    Jan 15, 2022
    Posts:
    46
    Hey so in my game (shown on the pic), I have a player (P) and an enemy (E). I've drawn red lines on the paths that I want to allow my enemy to take, and I want my enemy to move towards my player using these paths only. However, have no idea how I will implement this functionality in unity and code, maybe it's really simple, but I'm stuck. Please can someone help me out, thank you.
    enemy to follow paths.png
     
  2. warthos3399

    warthos3399

    Joined:
    May 11, 2019
    Posts:
    1,759
    Waypoints...
     
    anikataylor likes this.
  3. androvisuals_unity

    androvisuals_unity

    Joined:
    Mar 23, 2020
    Posts:
    47
    Nailed it.
    You basically want to have a set of points, set the destination to 1. When the distance to this very small you can set the destination to the next waypoint.

    Heres a good example of it in the documentation.
    Link
     
    anikataylor and warthos3399 like this.
  4. anikataylor

    anikataylor

    Joined:
    Jan 15, 2022
    Posts:
    46
    Thank you! I'll have a look into it since I've never done waypoints before