Hello everybody.

So heres my situation: I have a bunch of GameObjects with Rigidbodies on them, just flying through space. They should look like water or some other fluid that is beeing shot from some hose.

Kinda like this:

Now I want to connect them, so that I can give the fluid a mesh and a collider. This is all 2D of course.

I have tried a convex polygon which results in the blue polygon.

Thats great and all, but not what im looking for. Notice how the lower side of the fluid is completely ignored. Id like to achieve something like the green one.

Do you guys know any algorithms for this or a place where I can look for them? I have already searched around quite a bit but cant seem to find anything.

Thanks in advance

There are a couple of approaches depending on how accurate vs fast you need the algorithm to be. It may not be immediately obvious but there a huge variety of possible bounding polygons: research Alpha Shapes for the full nitty-gritty details.

You could explore algorithms like Delaunay Triangulation (slow!). I would search the edge of the graph for the next vertex that minimizes the angle between the previous generated edge. Consider that the two lines below are perfectly valid “outer edges” for a concave shape:

Alternatively, if you just want something that *looks cool* then I’d go completely the other direction and abandon polygons entirely. Look into “2D metaballs” for an approach that works well and on modern hardware is very cheap to evaluate.

Essentially you’d render a circular blob at each point using additive blending into a render texture. This results in a blobby-looking field representing a *function of the distance to the nearest point*. You can then draw that render texture using a threshold filter, giving you solid pixels anywhere the distance is below a certain value.

Here’s an example (it uses XNA but the approach would work in Unity): 2D Metaballs in XNA | NullCandy

Here’s a DirectX example of the same approach: http://developer.download.nvidia.com/presentations/2010/gdc/Direct3D_Effects.pdf