# How do I write a 2D follow Algorithm?

So, I’m making a 2D top-down RPG like Earthbound.

One hard thing that I can’t really wrap my head around is the party-following system. In Earthbound, your party acted kind of like a snake, with each character following the other perfectly, going around corners and such. I’m attempting to recreate that, and I’m at a loss. I might be over thinking it.

There are a couple ways I’m thinking of doing this:

1. Each time the followee moves, record exactly how the object moved that frame, and have the follower move that much the next frame. One problem I’d have to solve is to not send movements into collided objects, so that the party doesn’t become ‘bunched up’. Not sure how to deal with that, or how to actually record real distance travelled.

2. Have each party follower execute an a* following algorithm on the followee. This raises some performance red flags in my head, as well as tells me that it won’t work quite right; distance would naturally form in the party and we still have the collision to deal with.

Again though, I might be overthinking this a lot. Are there any examples in which this was done?

If it acts like snake, could just write snake.

Have the player remember a trail of the previous X spaces it was in, or counted as being in. Every time it moves to a new square, insert that into the front of the list and chop off the last. No need for follower#2 to track follower#1, since all paths are just shorter copies of the player’s. Or, every time the player moves more than D away from the last recorded spot.

Each follower tries to stand in the next space down the list (or X2, if you want them spread out a little.) That’s the difference from snake, where the body blocks rigidly follow. So follower#3 is always walking towards trailingList[3], as it changes. Since the player walked that way, you know the followers have a valid path.