Worm-like Behavior

I want to make a line of parts that move similar to chains or worms, where when the first part moves the next parts follow. I’ve tried using TweenService for the effect but it didn’t feel natural:

Is there anyway I can do this?

1 Like

You could use rope constraints…

This would work for most cases, but I want the parts to move from bottom to top. With rope constraints they would just fall to the ground.

Perhaps math.sin(x-position) which produce a wave and depending on its offset is it position/orientation of a normal. Depending on its position in the change is its x. And stop the math.sin(x-position) loop once it has reached it desired destination.

3 Likes

What if you delayed the tweening of the orientation? First, tween the positions of the parts. Then, around 0.25 seconds later, tween the orientation.

There’s also a more complex way to do it (I don’t currently know how to integrate it), but it involves setting a max speed of how fast each part can move. The topmost part would move a little too quickly compared to the bottom of the worm. Setting a maximum speed would simulate drag thus creating more realism.

Why not just change the 4 segments you have in the vid to about 20 (same length, more segments)? Might make things look a bit smoother. :slight_smile:

Try TweenService again, but with different easing styles and directions. I like using circular for a lot of things, but just try random styles.
You may also want to make it quicker, as the parts seem slow.

Realistically, when a snake slithers around, its body tends to follow directly behind the “segments” in front of it. This means the head kind of leads the way, and all the segments would eventually be at around the exact position the head was at some point in time.

If you want to apply a movement system like this, the key function would be determining how the head moves. @NovusDev actually gave a great potential example of this in his post:

It might seem a bit tricky to have the snake turn with sine/cosine calculations, but you can think of it like this: a sine wave has something called a midline, which is basically the middle of the wave. In your calculations, the midline doesn’t necessarily have to be straight. You can have it curve around in any (realistic) way you want, representing the snake’s path of travel:

As you can see, the midline represents the snake’s approximate “path” while the sine wave represents its actual path of travel, or its “slither effect”. At any point on the midline, you can apply an appropriate amount of rotation before applying the sine offset.

It shouldn’t matter if the snake’s path of travel is hardcoded or being determined in live time (e.g. following a character), you should be able to apply this rotation based on the direction the snake is moving at any given time.

This coding method might seem a bit complex for what it’s trying to achieve, but it’s going to be tricky to emulate realistic and accurate snake movement without relying on the physics engine in any way, so CFrame calculations and trigonometric functions are pretty much required in any context.

EDIT: Wrote this entire post without realizing you didn’t really need snake movement, oops. Worms do move in a similar way, but since you mentioned chains, I assume you don’t really want a “slither effect”, but just a sort of following reaction to the part rotating. As others have mentioned, I think you could mess around with the tween parameters and get better results. Also having the parts partially clip into each other might add to the effect a bit, but you’d have to fix any Z-fighting issues.

I had this same problem. The solution in this forum solved it. How to inverse kinematic a snake model