Logic for getting static mesh components to follow each other

Hi!

I’m working on a traditional ‘snake’ game, where each time the player eats an apple, their body grows by one segment.

At the moment, I have an array of static mesh components (just spheres), called ‘BodyBits’ - which gets added to, each time an apple is eaten.

In order to get each segment following the previous segment, on tick I’m using the function ‘Move Component To’, by taking an array element in BodyBits, and setting the target location as the previous element in the array.

This appears to work fine… for a couple of iterations (the spheres follow each other in a snake like fashion). But after eating a third apple, the thing breaks- and additional spheres stop following the previous sphere.

Now- I’m pretty sure the way I have things setup is not optimal (running through a loop on tick, and using a function ‘Move Component To’ which executes over a number of frames depending on how I’ve set the ‘over time’ parameter). So I’m looking for advice on how I might better be able to set up this chain like effect, with components being progressively added and automatically following the previous one.

Thanks very much for your time!

Ekar

Right now, I’m just using the mouse cursor position to place static meshes. On tick, I check the distance between the cursor and the last placed sphere. If it’s greater than ‘Distance’ var, I add another sphere, add that to the array, and delete the first index of the array based on whether I’ve gone over the ‘SnakeLength’ var.

So the next step is to update the spheres to points, and generate an updating spline mesh based off of those.

Thanks all for the support :slight_smile:

I’ve managed to get the snake updating now as spline meshes, which allows him to bend nicely as he moves around. A nice little goal reached… :slight_smile: The immediate issue is that the movement looks jerky (the snake jumps forward as new points are created, instead of smoothly following along the spline). I’ll need to look into what I can do there.

Any suggestions most welcome!

edit: actually, I’m starting to live with this movement (it’s works as a nod to the classic ‘snake’ feel).

Cheers :slight_smile: