Make Enemy follow Players path

I am trying to implement an enemy that would follow players path. For example player is moving around the map (2D) turning left, right, going back and fourth, and then after some time an enemy spawns and it should repeat that exact same path, same turns and so on.

My idea was to record some points every X[ms] and have an enemy move from point to point. But I am not sure if that is the cleanest way to do this. Other idea I had is to record player input but then if speed of enemy would be different then the one of the player it would not work.

Any suggestions are welcome.

I’ve never used NavMeshAgent, but I would imagine it has some functionality like this built into the class.

On the other hand, if I were to do this manually, I would start a list of waypoints. The start point being the first you add to the list, from there, just add points when the player changes direction and you might not want to start listening for the next point until the player has moved more than a certain distance away from the direction change point or you could get a noisy little area around the point, but that would be something to play around with.

Good luck