# Trigonometry Snake Movement

Welcome to our brand new Clickteam Community Hub! We hope you will enjoy using the new features, which we will be further expanding in the coming months.

A few features including Passport are unavailable initially whilst we monitor stability of the new platform, we hope to bring these online very soon. Small issues will crop up following the import from our old system, including some message formatting, translation accuracy and other things.

Thank you for your patience whilst we've worked on this and we look forward to more exciting community developments soon!

Clickteam.

Hello once more.

I've been studying the Maths tutorial download for a while now and had some success in creating various segmented things (chains, tentacles etc) using it's Trigonometry section.

That particular section features this snake, the head following the mouse pointer as the rest of the body flows behind it, but though the guide says it's relatively simple to do, it doesn't expand upon the previous tentacle section to explain how?

Would anyone be kind enough to share the formula needed to achieve such an effect? I can post a gif to explain a bit more clearly what the snake does if my description is insufficient

Thanks once again, I've gotten some great tips and pointers from this community so far

• Would anyone be kind enough to share the formula needed to achieve such an effect? I can post a gif to explain a bit more clearly what the snake does if my description is insufficient

This sort of thing you wouldn't need manual math, but just a for-each loop through the segments, setting their direction towards the segment in front of them.

So segment 1, behind head, follows the head. Segment 2 follows segment 1. Segment 3 follows segment 2. And so on.

A foreach loop can be done with Count > For each object action. There's a PDF guide Please login to see this link., on foreach loops and fastloops, but there's probably other tutorials.

Darkwire Software Lead Programmer (C++ & C#)

• Hi Phi, thanks for your suggestion

It works reasonably well, but it feels very clumsy and juddery compared to the version done with trigonometry from the tutorial, also when the caterpillar crosses over itself, none of the other sections move

This is the maths version, which is the effect I'm looking for, as you can see it's far more elegant and precise

• Try placing them closer together. And if the distance between the current and next one is too small, don't move them; stop the movement there and for the rest of the segments instead.

If all that isn't smooth enough, perhaps an Easing movement would do it.

Darkwire Software Lead Programmer (C++ & C#)

• That particular section features this snake, the head following the mouse pointer as the rest of the body flows behind it, but though the guide says it's relatively simple to do, it doesn't expand upon the previous tentacle section to explain how?

Have you looked inside the relevant frame events (called "Trigonometry: Worm")? That part of the runtime doesn't display any formulae the way the tentacle section does, but the frame events themselves are fairly well commented. The main maths happens in event #11, using an Atan2-based equation. Comment #3 gives you some suggestions for which parameters to change.