Following system

Godot Version

Godot 3.5.3

Question

Hey y’all! So, makin’ a Platformer RPG, planning to have a character that would follow the player like Tails in Sonic 3. How would i do that? What i mean is, is it possible to code something like his AI in Sonic 2 and 3? Of course, doesn’t have to use AI, it’s Godot 3 for god’s sake, but i just wanna know how to make the character follow you.

I’m thinking that you can have the player sharing his position with the other character. Then, that character can move to each point with a delay. With this simple system, when the player moves, the character will follow the same path as the player after a short time

Besides what @wender said, I’d add a Marker2D a few pixels “behind” that sonic character so the Tails character tries to go there instead of the Sonic position. But yes, I think you’d have to code an “AI” whose sole purpose is to try to reach that point, but controlling the character as any other player would (like jumping and running towards the point).

That is a good idea, the only thing is that if you are not careful enough, Tails could end up inside a wall or “floating” if Sonic is at the edge of a platform and the marker ends up outside it

i think i could merge both of your ideas. i could make the tails guy have the same controls as sonic but make them have like half a second of delay and make them go behind you.

Of course, this could work. However, depending on the specific game and levels your are designing, you may face some troubles.

Imagine that your player jumps into a moving platform and then jumps again into another. If the other character is told to perform the same actions disregarding the changes in the level, it may be possible that the platforms are no longer in appropiated positions to perform the jumps.

This is why my original suggestion was to move the character only based on previous positions of the player, without gravity or any other forces having any effect on it.

I believe that this approach is more flexible but it all depends on the specific levels your are making and the behaviour you want the characters to have. Good luck!

Yeah, it is pretty tricky, there are a lot of edge cases, like if the character jumps to a pixel perfect border, the second character might fall. Or it could miss an elevator or a moving platform, and it would have to wait for the next platform to arrive (or even fall to it’s death?)… it sounds easy on paper, but it’s really tricky.