Hi,
No need to ever tag me. I don’t look at alerts and I skim over all the new posts when I visit the forum.
I’m guessing you’re trying to do it by moving the head and having it leave a trail that everything else follows. One way to do it is add the head’s position to the front of an array, and just always position the body parts from an offset in the array. Finally you’d want a way to remove stuff off the back of the array when it gets too big.
The main complexity here is the offset calculation. A simpler formula could be (self.iid+1)*30 to just have each part be 30 frames (or 0.5 seconds at 60fps) behind the part before it.
(self.iid+1) gives 1,2,3,…etc
(self.iid+1)*32 gives a distance of every 32 pixels: 32,64,…etc
(self.iid+1)*32/100 if the head always has a speed of 100 this converts the distances to times
(self.iid+1)*32/100*60 Finally this converts the times to frames.
So events would look like this
Start of layout
— array: set size to (0,2,1)
— body: set offset to (self.iid+1)*32/100*60
Every tick
— array: push front head.x
— array: set at (0,1) to head.y
— body: set x to array.at(self.offset,0)
— body: set y to array.at(self.offset,1)
Array.width>6000
— array: pop back
You’d just move the head however you like. And at 60fps and the head moving at 100 pixels per second the body parts would be connected. There are likely many improvements to this idea but that’s the simple gist.
Your routine works very well! I've already implemented it here! :D
My only problem is that the objects can't maintain a minimum distance between them, always coming together at a coordinate (that of the head, since they all follow it) when the head stops.
Sorry to bother you again, but do you know how to fix this?