
Code for unreal and unity on github
This is something I’ve been playing around with for a couple of weeks now. I started off in unreal engine, but got annoyed after a while (my C++ skills aren’t that great and the long compile times kept getting in the way).
Anyway, the same basic approach seems to work in both, so maybe I’ll switch back once I have a more complete prototype working in Unity.
The main idea is to generate a grid of 2D points which represent the map in an abstract sense, and then build two objects from that: a sidewards-facing collision mesh (invisible to the player, handles physics) and a front-facing “display” mesh with a generated texture matching the created map. This is almost certainly not how the original Worms games were programmed, but it means we can use the engine’s builtin physics engines without having to implement some custom per-pixel collisions.
The collision mesh is generated with a marching squares implementation based on the map representation Sebastian Lague’s “Procedural Cave Generation” youtube videos were very helpful when figuring out this approach. Instead of starting out with random noise, though, the algorithm uses a modified version of perlin noise, thresholds it, and then picks out continuous areas to turn into terrain (ref: [1] [2]). Then a few iterations of dilate and smooth operations are run
Here’s the generation working on a larger scale: as you can see it could probably do with a bit more smoothing (or mayber a larger amount of smoothing on each pass)

And here’s what the collision mesh ends up looking like:

Probably the most fiddly part of the whole thing was making sure all the triangles in the 16 different marching squares cases were ordered correctly (clockwise for unity, anticlockwise for unreal IIRC) but once that was out of the way then the mesh behaved pretty well