Scheduled NPC Paths (like Stardew Valley)

Any advice on how to make NPCs walk along a specific path, pause for a specific amount of time and then continue on a path?

Thanks :slight_smile:

The Technique I use is called “Way Points”. It’s basically a list of target points, and each point has a delay associated with it.

I start with the first element and the object continues moving in the direction of that point. Once it reaches that point, it waits for the delay associated with that point and then moves to the next point.

Example code:

public class WayPoint
{
    int X;
    int Y;
    int DelayInMilliseconds;
}

List<WayPoint> WayPoints = new List<WayPoints>();
int CurrentWayPointIndex;

In the code for moving my object I check to see if I’m at the position of the way point, if not, keep moving towards it. If I reach that point, I wait and then increment CurrentWayPointIndex and if I reach the end I set it back to 0.

My actual system is a little more complicated as I can control angles of the objects (so they are facing the direction of travel), whether to reverse the direction at the end, etc… (so it goes up the list then down the list rather than just wrapping around).

1 Like

Thanks.

I’ll look into this.