Hello, I’m trying to make a snake like enemy that is made of 7 segements, where they all copy the movements of the front segment, but delayed from each other.
However, they always end up desyncing, even when I only use events that aren’t frame depended, they still copy each others movements, but over time it becomes off. (I’d like to show the issue but it’ll only let me post 1 picture)
Does anybody know a method to make this consistent? Would I have to store positions? Would I have to use tweens? Thank you.
I don’t know how you are doing it right now, and there are probably many ways to do it, but one simple way that comes to my mind is to lerp the position of the follower objects based on the angle and distance.
For instance:
change the X position of Follower 1 to lerp(Follower1.CenterX(), Leader.XFromAngleAndDistance(Leader.Angle() + 180, 30), 0.1)
change the Y position of Follower 1 to lerp(Follower1.CenterY(), Leader.YFromAngleAndDistance(Leader.Angle() + 180, 30), 0.1)
Where +180 make it follow the leader, 30 is distance, and 0.1 is how tight/loose the following is, so you would want to adjust 30 and 0.1 to your liking.
Then repeat for the other ones attaching the next follower to the previous one:
change the X position of Follower 2 to lerp(Follower2.CenterX(), Follower1.XFromAngleAndDistance(Follower1.Angle() + 180, 30), 0.1)
change the Y position of Follower 2 to lerp(Follower2.CenterY(), Follower1.YFromAngleAndDistance(Follower1.Angle() + 180, 30), 0.1)