Hiss Highness: Procedural Snake Game with Terrain-Accurate Slithering (No Raycasts!)

A snake hunting game with procedural slithering, terrain following, and mobile touch controls.

Play :snake: Hiss Highness: Rodent à la King :crown: 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:

  1. Single cylinder with bones - worked great in 2D, but I just couldn’t get natural movement with bending on all axes
  2. Multiple connected cylinders - joint gaps looked awful
  3. Tube geometry following a curve - getting closer…
  4. 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 :mouse_face:) 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 :sweat_smile:)
  • Procedural terrain with simplex noise heightmap and normal map generation
  • Cheap grass shader using onBeforeCompile with 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 AnimationMixer for 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


Hope you enjoy the game!

4 Likes

Nice and quite playable.

The three things that I like most were:

  • how Hiss Highness curves around stones
  • how mice panic with (!) – I secretly hoped that the mice would not join forces and attack back
  • I was chasing a mouse that run away for quite a long time until i realized it was a tiny coffee spot on the screen

Sometimes before climbing steeper slopes the front section of the ground gets frustum culled.

1 Like

Very nice, the rearview mirror is a nice touch

Not sure about the reversing mechanic though, you can “drive” your snake backwards that is.

2 Likes

@Usnul thanks. Glad you like it.

Haha, yes, I totally made that up :smiley:

I was sold at the name of the game and then the home screen.

1 Like

@seanwasere glad you liked the copy! Especially as I claim authorship of that.

But the splash-screen graphics are, obviously, ChatGPT.

This game is HISSterical!

I really like that you are able to share the code to your programs on CodePen. These provide extremely helpful examples for coders who want to create programs with similar features.