Follow the leader - like Phantasy Star

Hey all!
I’m rather stumped by this, and I’m wondering if I could get some ideas.
I am trying to get a character to follow behind the main character, similar to how things work in ye olde Phantasy Star on genesis:

It’s at 1hr, 22m 44s :slight_smile:

The thing that has me stumped, is that the characters following the leader seemingly follow the exact path of the leader but delayed by several steps.

I would like to replicate this.

How could this be achieved? Do the followers keep a list of button presses from the player but only run them several steps after the leader moves? My leader moves only X and Z axes, but unlike phantasy star, I’m moving the leader using transform.Translate(dir * speed * deltatime).

One of my ideas is to have the leader keep a list of movements for x number of seconds, and the followers can read off that list. I’ve also tried stuff like targetting a position behind the leader, but that is not what I’m looking for.

Many thanks!

Each follower basically has a target destination that is updated every N steps. Either they inspect the last target set by the one they’re following, or that character updates the next follower.

So the leader sets the next character’s target to its current position, walks the minimum distance of one push of the stick, say 4 steps, then tells the next character to move to the target. If the leader is still moving, update every N steps, and keep pushing the follower every N steps after setting a new target for them to get the updated target/direction.

This looks fine in my head. Code, probably not so clean. See if it at least gives you some ideas :slight_smile:

1 Like

Hi Orb! Thanks! That sounds like something I can test out tonight :slight_smile: Cheers!

To conclude this thread, I tested out Orb’s suggestion, and it works! However, I could not figure out the jittering I was getting between the followers and the leader, it had to be something about timesteps and sample resolution. Tested FixedUpdates etc didn’t really get rid of it.

In the end, what I did was to keep, on the leader, a list of previously travelled positions (e.g. keep last 100 travelled positions).

Followers then call a function on the leader to retrieve their position/orientation by interpolating the saved positions in the list. Works surprisingly well, though I still get mild jitters. On the actual device the jitter is near imperceptible, and I’m hoping the character animation will hide it. If not, perhaps some filtering could solve it.

Cheers!

I’m not entirely sure what the jitter is from, but it might have something to do with how you move them. I’m getting no such jitter with a simple transform.Translate() on an animated sprite though. Check the forums for general jitter-related questions :slight_smile:

Did you do a * Time.deltaTime; ??? That is supposed to stop jittery updates lol.

Are you getting a consistent framerate? When you run in the editor, you get CRAZY framerate spikes - 60hz to 500hz. Inconsistent framerate/update rate is the primary cause of jitter seen in most games, and it’s REALLY nasty to solve. It’s likely why you aren’t seeing this issue on your device. Discussed this in more depth in my chapter “Believable Dead Reckoning for Networked Games” in Game Engine Gems 2.

Good luck,
Gigi

@orb : I think it has to do with when the values are sampled from the leader - if I’m using fixed update to do the sampling, the followers will sample the leader’s position 50 times a second (using default 0.02s step) But the leader, moving with update, runs at over 100fps - i.e. timestep in update can be shorter than 0.01s - nyquist rate means my sampling rate is way to low to reconstruct the leader’s path; hence follower’s result is aliased.

Writing this down, I don’t think i actually tried moving the leader using fixed update, but I am not sure if that’s a good idea…

@N1warhead_1 : Definitely used deltatime at the proper places!

@anon_3573859 : My framerate is definitely quite inconsistent. On my android device, if I was continuously providing touch input, the framerate keeps up. But when I do not give any input, it appears the cpu slows down. Framerate doesn’t appear to slow down, so probably it’s still above 60fps, but the jittering definitely comes in. With my new setup, it actually looks very alive when it happens, which is why I ran with it.

Thanks for the reading suggestion, will check it out shortly!

Huh, moved all my time dependant code to fixed update and… all the jitters are gone… guess it really is a sampling thing? On the flip side, now that the movement is done inside fixedupdate, it doesn’t seem quite as smooth .graah

^ This. Consistency is > performance when it comes to the perception of movement & rotation. Our brain has the most advanced real-time, predictive calculus interpolators ever invented. If an enemy changed course even slightly, we’d have to adjust, IN ADVANCE of our movement. Even the slightest stutters causes re-interpolation, AND worse, raises flags to make your brain take notice. Double whammy.

Hint - It’s better to be in the WRONG place at the WRONG angle than to be 90% closer with jitter.

Gigi