I built a fluid simulation extension to the rigid body physics system. It’s separate, but connected. The system is split into 3 conceptual parts:
Fluid - the medium that’s being simulated
Effectors - things that… affect the fluid
Obstacles - things that blocks the propagation
The obstacles piggy-back off the rigid body physics, if you want a physics body to block the fluid - you just attach the FluidObstacle component to its entity, making integration effortless.
The fluid is a scrolling grid in world space. Typically you would making it follow the player of the camera. When the Transform attached to the FluidComponent moves, the grid scrolls in discrete steps with a bit of hysteresis. The net effect is that things “just work”.
The obstacles are voxelized into the fluid.
Following effects exist:
GlobalFluidEffector - this is your typical “wind”, with gusts and variation across the grid.
ImpulseFluidEffector - things like explosions and fans. Exerting linear force in a spherical area.
WakeFluidEffector - possibly the coolest one. Injects force following an object. Think thrown projectile or a moving car.
Simulation is entirely CPU-side, but it’s optimized to the edge of what’s possible in pure JS, running pretty comfortably under 2ms with 32x16x32 resolution.
I have some limited experience with white water canoeing. If it gets rough and you need to take a break, you’ll be looking for a big enough obstacle in an otherwise strong current. Because right downstream of the obstacle, you’ll find a “backwater”(?), an area where the direction of the current is locally reversed, from downstream back to the back side of the obstacle, where you can effortlessly “park” yourself for a while..
Maybe this is just a matter of cone spacing resolution, but I would have liked to see the “backwater” effect more clearly.
Can you get me a image or some kind, maybe a diagram?
I’d be curious to reproduce this, there is reflection in the solver and a lot of effort went into energy preservation, so I’m pretty sure it can be achieved
The main point of a sim like this is to make things look pretty and give a bit of secondary motion to the world, not accuracy per-se, but I believe that accuracy often gives most interesting results visually when it comes to simulating real-world phenomena.
Also, it’s not very clear from the examples at all, but the simulation is 3d, not 2d. For water sim the implication would be lack of gravity and true containment, so it’s less suitable for liquids.
I think for liquids you’d want something particle-based or a bit more discerning than just “fluid” / “obstacle” encoding. It’s perfect for air though.
On a similar note, I also happen to be a former hangglider pilot. “Obstacles” in the course of a current (called wind) come in the shape of mountains, behind which you’ll find the same type of eddies, albeit on a much larger scale. Think of a Karman Vortex Street, which can even be found on a global, if not cosmic scale, see this:
I took a video of this effect awhile back when standing on a bridge looking downstream. As the water passed the pillars, it would curl in, creating a space of stationary water in the “shadow” of the pillar.