A snake hunting game with procedural slithering, terrain following, and mobile touch controls.
Play
Hiss Highness: Rodent à la King
on CodePen. Slither. Spot. Dine. →
The Journey
This started with me looking for a proper slithering snake in Three.js. What began as a fun experiment turned painful by my 4th complete redo:
- Single cylinder with bones - worked great in 2D, but I just couldn’t get natural movement with bending on all axes
- Multiple connected cylinders - joint gaps looked awful
- Tube geometry following a curve - getting closer…
- Final approach: Verlet-style segment chain with procedural tube generation - winner!
The Snake (class Snake)
I’m very happy with the slithering motion. It’s not hyper-realistic, but believable enough while maintaining excellent performance.
Key features:
- Verlet-style position chain (head leads, body follows)
- Procedural tube geometry rebuilt each frame
- Sine wave slither applied perpendicular to spine
- Terrain normal sampling for proper ground conforming
- Obstacle avoidance with sliding (no physics engine!)
- Backward movement where the tail leads
- Smooth speed transitions with lerped parameters
Check out how it flows around rocks. Not too shabby, I think.
And another cool thing: no raycasting in the entire game.
Terrain height and normals are sampled directly from pre-computed Float32Array heightmaps using bilinear interpolation. Obstacle collision is just distance checks against a simple array of {x, z, radius}.
This is a case of smart data structures beating brute-force raycasting. This approach yields buttery smooth performance even on mobile at max FPS with 30 snake segments, 15 mice, and 50 obstacles.
The Head (class SnakeHead)
I scoured the net for a free snake head, rigged and animated. Couldn’t find anything suitable.
I wanted to avoid the Blender rabbit hole (no pun intended
) at all costs… so the cost was writing the head entirely in code. A few days worth of work, but worth it.
Procedural features:
- Shaped skull with vertex deformation
- Animated lower jaw with hinge pivot
- Eyes with vertical slit pupils that look around or follow the camera in Orbit mode
- Eyelids that blink
- Forked tongue that flicks out randomly
- Fangs and teeth visible when mouth opens
- Vertex colors for belly/back color blend
Other Features
- Mouse prey AI with idle/wander/flee states and vision cone detection
- Frame-rate independent movement (learned this the hard way upgrading to a 240Hz monitor
) - Procedural terrain with simplex noise heightmap and normal map generation
- Cheap grass shader using
onBeforeCompilewith FBM noise + slope-based dirt blending - Dual-stick mobile controls (nipplejs) - left stick forward/back, right stick turning
- Picture-in-picture snake-cam
- Pinch zoom on both main view and snake-cam
Performance Notes
Runs smooth on mobile. Key decisions:
- Single shared
AnimationMixerfor all mice - Frustum culling check before updating distant mice
- Pre-allocated vectors everywhere (zero GC pressure in update loops)
- Instanced mesh for obstacles and particles
- Direct heightmap sampling instead of raycasts
What I’d Do Differently
- The procedural head was rewarding but time-consuming. I don’t think I could do another one of these from scratch.
- Would explore GPU-based tube generation for even more segments.
Credits
- Mouse model from Sketchfab
Hope you enjoy the game!

