Table of Contents
- Introduction
- Quick Start Guide
- The Demo Scene
- Core Components
- Configuration
- Limitations
- FAQ & Support
1. Introduction
Thank you for choosing Easy 2D Worm! This asset is a lightweight, physics-based solution for creating organic, following creatures like snakes, worms, tentacles, or dynamic tails in Unity 2D.
Unlike standard physics joints which can be unstable or heavy, this system uses a custom, highly optimized "follow-the-leader" algorithm. It calculates hundreds of segments instantly via lightweight array math without spawning a single GameObject for the body, ensuring maximum performance and zero hierarchy clutter.
2. Quick Start Guide
- Add the Prefab:
Drag the Worm.prefab from the Easy 2D Worm/Prefabs/ folder into your scene. - Move the Head:
Enter Play Mode and move the Head child object. The body will automatically follow smoothly. - Customize:
Select the main Worm object and adjust the Length, Quality, or Width Curve in the Inspector to dynamically change the creature's size and shape.
3. The Demo Scene
The asset includes a ready-to-use demo scene located in Easy 2D Worm/Demo/Scenes/Demo_Worm.unity.
Features Showcase:
- Organic Wander Mode: The worm organically slithers within the camera bounds using Perlin noise and sine waves.
- Interactive UI: Change the worm's length, width, and speed in real-time using sliders.
- Preset System: Use the UI buttons to load different
WormPreset ScriptableObjects (Snake, Tentacle, Maggot) to see how versatile the rendering is. - Dynamic Shadows: Includes advanced shadow scripts that mimic the main body's curve, scale, and tapering.
- Custom Shaders: Demonstrates the included Smooth Circle and Smooth Line custom shaders for pristine, anti-aliased visuals.
4. Core Components
WormController: The main brain of the system. It calculates the entire physics chain internally via arrays, manages the dynamic scaling, and visually updates the Line Renderer. WormPreset: A ScriptableObject that allows you to easily save and load body configurations (Lengths, Curves, Gradients, and Shadow Settings). Worm Prefab: A pre-configured setup containing the Controller, a standalone visual Head, and a Body object with the Line Renderer.
5. Configuration
All customization is done directly in the Unity Inspector on the WormController component.
- Length: The total physical distance of the worm.
- Body Width: The base thickness of the line.
- Quality: The number of physics points calculated. Higher quality means smoother curves.
- Body Width Curve: The shape of the body. (Left = Head, Right = Tail).
- Render Head On Top: Visual setting that reverses the drawing order, ensuring the head overlaps the tail natively without Sorting Layer hacks.
6. Known Limitations
To achieve its extremely high performance, the system has a few intended native limitations:
- Tight Turns Folding: Unity's Line Renderer natively struggles to draw sharp acute angles when points overlap. Very tight turns may cause the visual line to fold slightly.
- Sudden Length Increases: Because the worm uses "pull-only" string physics, instantly snapping the length to a huge value creates natural slack. The segments will bunch up until pulled. (Pro-tip: Smoothly lerp the length variable over time, as demonstrated in the DemoManager).
- Transparency Overlap: Because the Head and Body are separate overlapping meshes, applying partial transparency (low alpha) will cause the joint where they connect to become visibly darker.
- Custom Shader End Caps: Unity Line Renderers stretch UVs on their native "End Cap Vertices," which breaks custom shaders. This is why the system uses a standalone Head object to guarantee a perfect circular cap.
- No Body Collisions: The body segments are purely visual/kinematic. They do not have colliders, as updating hundreds of colliders per frame would cause significant CPU overhead. If you need collision events (e.g., eating an item), place a 2D Collider exclusively on the Head object.
- Strictly 2D: The physics calculations actively ignore the Z-axis to prevent the worm from spiraling away from the camera.
7. FAQ & Support
Q: I moved the "Worm" parent object, but the body didn't wiggle.
A: Moving the parent object moves the entire coordinate system rigidly. To see the physics effect, you must move the Head object relative to the body.
Q: Can I apply a patterned Texture (like scales) to the body?
A: Yes, but you must replace the included custom material with a standard Unity material (e.g., Sprites/Default) and set the Line Renderer's Texture Mode to Tile. Our custom anti-aliasing shaders strictly require Stretch mode to calculate the smooth edges correctly.
Q: Why does my Line Renderer gradient/curve look backwards in the Inspector?
A: If you enable Render Head On Top, the system draws the line from Tail-to-Head to ensure the head visually overlaps the body. However, the WormController script automatically reverses this for you. Always design your Curves and Gradients assuming Left (0) is the Head, and Right (1) is the Tail.
Leave a Rating
If Easy 2D Worm saves you time and helps your project, please consider leaving a 5-star review on the
Asset Store page.
It helps the asset grow immensely.
Need Support?
Email is the fastest way to reach me:
pixeladderdev@gmail.com
(Please include "[Easy 2D Worm]" in the email subject line.)