How can I achieve a snake like motion where the body follows the head?

Started by
11 comments, last by haphazardlynamed 17 years, 10 months ago
Ok, after a good nights sleep everything's making much more sense.
Thanks for all your insight and tips :)

What I have now a spring based system with a rest length of 20 (that's the links current size) and indeed there's a problem when the snake change direction drastically.
I will try to prevent it from acting like (making it only change direction in 90 degrees angles).

I'm still not sure i understand the difference between haphazardlynamed's method and a spring calculation.
I've adjusted the code in the link Pistachio supplied and I must say i'm not even sure if it's considered a spring simulation or simply calculating it the way haphazardlynamed suggested... :)
Here's the code i'm currently using:

for (i=1; i<MAX_LINKS; i++){	force_dir = Body[i-1] - Body;        // length is a sqrt of the dot product	CurrDistance = force_dir.length();	intensity = (CurrDistance-LINK_DISTANCE)/CurrDistance;	ComputedForce = force_dir*intensity;	Body+=ComputedForce;}


So basically, it seems things are working pretty well now, i'm justn ot sure what i'm doing right :)

Thanks again for taking the time to help!
ehud.
Advertisement
Holy Geometery Wars Batman!
The cheese stands alone.
Quote:Original post by ehudros

I'm still not sure i understand the difference between haphazardlynamed's method and a spring calculation.
I've adjusted the code in the link Pistachio supplied and I must say i'm not even sure if it's considered a spring simulation or simply calculating it the way haphazardlynamed suggested... :)
Here's the code i'm currently using:


My suggestion is like a simple subcase of doing a spring calculation, in this case the springs are infinitly stiff and don't 'spring' at all. The overall algorithm is basically the same idea though, just leaves out the springiness calculations.
The code in Pistacio's link is also esentially the same idea: stiff springs.
The main difference between what I suggested and the Jakobsen article, is that the article is general purpose joints simulation; while my suggestion uses one-way constraints between the joints.(mainly because you wanted the head of the snake to be in control of the tail, with the tail being totally passive). Once again this can be considered a subcase situation.
They're all pretty closely related approaches.

This topic is closed to new replies.

Advertisement