2 edited tags
| link
1
source | link

How to Create Snakelike Objects

I am working on a 2D action platformer in Python, though my question is a general one about creating snakelike objects which move in a variety of patterns.

I have noticed this kind of object in many 2D games. For example, this boss in Contra has snakelike arms.

enter image description here

And this enemy from Super Metroid clearly seems to be composed of multiple segments.

enter image description here

I want to create snakelike objects in my game, though I don't know where to begin or what I may need to add to my physics engine to support them.

So far, all my enemies and hazards consist of single sprites and are programmed using simple attributes like velocity, acceleration, parametric curves, etc.

Maybe I need to create a class for the segments, designate one segment instance as the leader, and update the positions of the other segments based on the position of the segment in front of it. But how do I program different patterns of movement? Do I need to learn about so-called joints and implement them between the segments? I currently don't have them in my engine.

I know I could easily create a segmented object where each non-leader segment is moved to the previous position of the segment in front of it (like in classic Snake, described here), but I want more complex patterns than this. Sometimes I may want the object to be flailing from an anchored point, and other times I may want it to be following some pattern across the screen.

I really don't know where to begin in trying to create this kind of object and would greatly appreciate any advice.

How do you implement snakelike objects with a variety of movement patterns?

(Given the ubiquity of this kind of object in games, I was surprised that I couldn't easily find much about it online. I think a detailed write-up on it would be cool.)