Snake game-type following behavior

Started by
3 comments, last by Esys 13 years, 4 months ago
I'm currently prototyping a top-down zombie survival game in which the player is tasked with finding survivors in a city before a timer expires. I'd like that once the player finds a survivor (and subsequent survivors), they follow the player in a manner that resembles the following-movement of the old Snake games.

The method that kind of works is I insert the most recent position of the player in a list, and iterate through the list, assigning more recent positions to the followers. The only problem is that if the player or survivor sprite is, say 16x16, and the player movement speed is less than 16, the images overlap.

I'm looking for a method that will allow a buffering space between the player and each survivor, and still have the movement behavior I'm looking for.

Thanks in advance.
Advertisement
Quote:Original post by Esys
I'm currently prototyping a top-down zombie survival game in which the player is tasked with finding survivors in a city before a timer expires. I'd like that once the player finds a survivor (and subsequent survivors), they follow the player in a manner that resembles the following-movement of the old Snake games.

The method that kind of works is I insert the most recent position of the player in a list, and iterate through the list, assigning more recent positions to the followers. The only problem is that if the player or survivor sprite is, say 16x16, and the player movement speed is less than 16, the images overlap.

I'm looking for a method that will allow a buffering space between the player and each survivor, and still have the movement behavior I'm looking for.

Thanks in advance.


Just let X positions be unused, so rather than placing the survivors at oldplayerposition[survivorid] you place them at oldplayerposition[(survivorid+1)*x] increase x to get a bigger space between them.
[size="1"]I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!
I was just working on this in 3d.

I haven't implemented it yet but I'm going to try setting the 'links' of the snake to initial positions at then spacing that I want, then keep an array of the 'head's last movement-path vector, pushing the older ones down the line until it gets to the tail and pop the last one. this would give the effect that they keep the same spacing and basically follow the head's path.
You can use a simple decision.

If survivor is more than 16 units to the player (or other survivor in front)

Move towards it.

else

Do nothing.
I don't play MMOs because I would become addicted
Quote:Original post by SimonForsman
Quote:Original post by Esys
Stuff...


Just let X positions be unused, so rather than placing the survivors at oldplayerposition[survivorid] you place them at oldplayerposition[(survivorid+1)*x] increase x to get a bigger space between them.


This seems to work the best, 'tho it may get a bit hairy later on when towing 10 or more followers around.

Quote:I was just working on this in 3d.

I haven't implemented it yet but I'm going to try setting the 'links' of the snake to initial positions at then spacing that I want, then keep an array of the 'head's last movement-path vector, pushing the older ones down the line until it gets to the tail and pop the last one. this would give the effect that they keep the same spacing and basically follow the head's path.


I tried this method, but ran into a snag. Imagine the first move made is one step to the left or right. The follower actually needs to move forward one, even though the "last move" was to the side.

This topic is closed to new replies.

Advertisement