World‑Space Cylinder Side‑Aligned to Arbitrary Plane Normals

I’m working on a snake game and needed a way to generate a cylinder‑like body segment that:

  • Rests along an arbitrary surface (not just Y‑up)

  • Aligns to a plane normal in world space

  • Maintains roundness at the contact surface

  • Optionally sags along its length

  • Can be capped on either end (or both)

I searched around quite a bit and nothing I found was really plug‑and‑play for this use case, especially once arbitrary plane normals and ground contact were involved.

So I built a helper that:

  • Constructs the cylinder directly in world space

  • Uses a plane normal + point to enforce contact via projection

  • Keeps the underside round by lifting the centerline by the local radius

  • Supports optional caps per end

  • Works at any orientation (camera movement doesn’t affect deformation)

This may turn out to be useful beyond the snake case (pipes, cables, terrain‑hugging meshes), so I figured I’d share it in case it helps someone else.

Find it on CodePen →

2 Likes