Official guide · Finding Needle in the Stack
How the haystack works: a diggable 3D heap in your browser
The haystack in the game is not a picture and it is not a hollow shell. It is a solid shape that changes as you dig, and the tunnels you make stay where you made them. This article explains, without too much jargon, how that works and what the game has to do every time you pull out a handful of hay.
A grid of density instead of a pile of objects
The obvious way to build a haystack would be to place millions of separate pieces of hay and move them around. That would bring any browser to its knees. Instead, the game stores the haystack as a three-dimensional grid of numbers. Each cell holds a value from 0 to 255: 0 means empty air and 255 means packed hay.
The grid is 88 cells wide, 40 tall and 88 deep, with a cell every 0.3 metres. That is 309,760 cells in total, covering a space of about 26 by 12 by 26 metres, which comfortably holds a dome roughly 21 metres across and almost 10 metres tall. The game counts this volume as 5,000,000 "pieces of hay", which is the number you see going down at the top of the screen as you dig.
Turning numbers into a surface
Numbers in a grid are not something you can look at, so the game turns them into a surface. It uses a technique called Surface Nets, which finds the boundary between "air" and "hay" and builds a smooth skin along it. Think of it as shrink-wrapping the part of the grid where the numbers cross the halfway point.
This is why a tunnel looks smooth and round instead of blocky. It is also why digging next to an old tunnel blends the two craters together.
Chunks: only redo what changed
Rebuilding the whole surface on every dig would be far too slow. So the grid is split into blocks of 16 cells on each side, which the game calls chunks. When you dig, it lowers the density around your tool and re-makes only the chunks that the dig touched. Everything else is left alone.
That is the main trick behind a heap that reacts instantly even on a phone: the amount of work depends on how much you dug, not on how big the haystack is.
The straws on top
A smooth surface alone would look like a lump of clay. To make it read as hay, the game dresses it with thousands of small straws drawn as instances. Instancing means the graphics card is told "draw this straw shape many times at these positions" in a single request, which is far cheaper than thousands of separate objects. Loose straws also fly off when you dig, to give each pull some weight.
When hay falls
If you dig a cavern and cut a piece of hay free from the rest of the stack, that piece no longer has anything holding it up. The game keeps checking for hay that has lost its connection and lets it fall, which is why you should be careful about hollowing out a roof above your own head. The tips in How to find the needle cover how to dig safely.
Saving a haystack
Because the whole haystack is just that grid of numbers, saving it means saving the grid. The game stores it in your own browser, together with your money, tools and position, so every tunnel is still there when you come back. More on that in Saving, exporting and moving your save.
Built with
The game runs on Three.js, a popular open-source library that lets web pages draw 3D graphics with WebGL. There is no server doing any of this work: everything happens on your device.
Ready to dig?
Free in your browser on PC and mobile. Your progress saves as you play.
Play Finding Needle in the Stack