Sign in to follow this  
Esys

Snake game-type following behavior

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this