I'm wondering how objects follow each other where they move over the previous position of the object in front of them. When the leading object stops, all that are following should stop at their position. So how is this achieved?

Like so:

Edit:
What I want to achieve is that all the following objects "walk" the path the leading object in front is taking. All the other objects just move at the speed of the leading object ( this would be by passing the velocity vector to all the following objects). But how do I let all the objects move/pause over the path while maintaining their distance from each other as well.

Path->WayPoints becomes bigger and bigger the longer the game goes on. If your Snake exists for quite some time, you need to delete the last WayPoint whenever the last element of the Snake has passed the second-to-last WayPoint of Path. Remember to also reduce distanceFromEnd in all MovingObjects of Snake accordingly.

Let's say I would want to drag my leading object with my mouse( not that I want to, but let's say that I do ). How would that work with your example?
–
SidarAug 24 '12 at 14:03

The list of objects could move by first letting the first element move from its current position in a given direction (with a given speed), and then letting all the other elements move from their current positions in a direction specified by their current position and $this->previousElement->getPosition(). If you drag your first element somewhere, you just have to call its setPosition() method. When the list is rendered, the other objects will change their path to follow their predecessors.
–
BerndBrotAug 24 '12 at 14:11

Correct me if I'm wrong but wouldn't that also result in the objects following taking shortcuts as they change direction? ( like in the lower part of the image i've given). It sounds like they wouldn't follow the path of the object up front. Instead they would go into the direction of the leading object infront of them as much as possible. Causing the objects going off path and taking shortcuts?
–
SidarAug 24 '12 at 14:26

Yes, that would indeed happen with this particular implementation. I posted the answer before you added your pictures, so let's try again ...
–
BerndBrotAug 24 '12 at 14:35

Essentially you'll need two data structures (logical, intrusive, or real, depending on the rest of your code). The first will track the chains of objects, and the other the path.

Chain Simply you need to know which objects are following other objects. In the simplest case this will simply be A follows B, but could include more followers. There is a designated leader in the chain.

Path For each chain you'll need a path. Depending on how your game works will determine how this is structured. In most cases it will be some kind of linked list. This will track the positions that everybody in the chain needs to follow.

Now, the leader in the chain will be adding items to the path. Each time it moves it will add something to the head of the list. Each object in the chain remembers where on the list it is. When it comes to moving it simply moves to the next item in the list (interpolated appropriately if necessary). As the last item in the chain moves past an item in the list, that item can be dropped (it will be at the tail).

Metaphorically the leader leaves a breadcrumb trail for its followers. The last follower in the list consumes the breadcrumb.

Whether your list contains individual points, or just the vertices of a path, or something else, is determined entirely by your game engine. But in any case I don't see that you'll be able to avoid the list itself.

I know what A* is, not what I'm looking for and far too heavy for something that seems rather far more simple.
–
SidarAug 24 '12 at 13:57

your answer is not even close to what the correct answer is. A* is an algorithm to find a path. While he doesn't want to find anything, he just wants object to follow each other exactly in every position last object was.
–
Ali.SAug 24 '12 at 21:52

When I originally answered the question it wasn't fixed to clarify more / there wasn't a picture to show what he meant. I just read the first 2 sentences and figured he was having multiple entities trying to track something, not follow a path. Sorry for the bad answer I guess
–
thedeadlybutterAug 25 '12 at 6:05

I did say follow each other =P not move to a point.
–
SidarAug 25 '12 at 17:08